using System;
namespace OOP_CONSTRUCTORS
{
class Animals
{
private string name;
private string sound;
public const string shelter = "Aibo's Hangout";
public Animals()
: this("No Name", "No Sound") { }
public Animals(string name)
: this(name, "No Sound") { }
public Animals(string n, string s)
{
setName(n);
SoundCap = s;
Console.WriteLine(SoundCap);
Counter = 1;
Console.WriteLine(Count);
}
public void introduced()
{
Console.WriteLine("Voice of {0} sounds like {1}", name, sound);
}
public void setName(string n)
{
int i = 1;
foreach(char c in n)
{
if (!char.IsLetter(c))
{
i = 0;
}
}
if (i == 1)
{
name = n;
}
else
{
name = "No name";
Console.Write("Error name can only contain alphabets");
}
}
public string getName()
{
return name;
}
public string SoundCap
{
get {return sound;}
set
{
if (value.Length > 10)
{
sound = "No Sound";
Console.WriteLine("Sound length is to long");
}
else
{
sound = value;
}
}
}
public int Count;
public int Counter
{
get { return Count; }
set
{
Count += value;
}
}
public string Owner { get; set; }
class Program
{
static void Main(string[] args)
{
Animals aibo = new Animals();
aibo.introduced();
Animals aibo1 = new Animals(name : "balto");
aibo1.introduced();
Animals aibo2 = new Animals("balto", "Woof Woof");
aibo2.introduced();
Animals obj = new Animals("Gray", "Angryroar");
Console.WriteLine(obj.getName());
obj.Owner="Nigga";
Console.WriteLine("{0} owns {1}",obj.Owner,obj.getName());
Console.ReadKey();
}
}
}
namespace OOP_CONSTRUCTORS
{
class Animals
{
private string name;
private string sound;
public const string shelter = "Aibo's Hangout";
public Animals()
: this("No Name", "No Sound") { }
public Animals(string name)
: this(name, "No Sound") { }
public Animals(string n, string s)
{
setName(n);
SoundCap = s;
Console.WriteLine(SoundCap);
Counter = 1;
Console.WriteLine(Count);
}
public void introduced()
{
Console.WriteLine("Voice of {0} sounds like {1}", name, sound);
}
public void setName(string n)
{
int i = 1;
foreach(char c in n)
{
if (!char.IsLetter(c))
{
i = 0;
}
}
if (i == 1)
{
name = n;
}
else
{
name = "No name";
Console.Write("Error name can only contain alphabets");
}
}
public string getName()
{
return name;
}
public string SoundCap
{
get {return sound;}
set
{
if (value.Length > 10)
{
sound = "No Sound";
Console.WriteLine("Sound length is to long");
}
else
{
sound = value;
}
}
}
public int Count;
public int Counter
{
get { return Count; }
set
{
Count += value;
}
}
public string Owner { get; set; }
class Program
{
static void Main(string[] args)
{
Animals aibo = new Animals();
aibo.introduced();
Animals aibo1 = new Animals(name : "balto");
aibo1.introduced();
Animals aibo2 = new Animals("balto", "Woof Woof");
aibo2.introduced();
Animals obj = new Animals("Gray", "Angryroar");
Console.WriteLine(obj.getName());
obj.Owner="Nigga";
Console.WriteLine("{0} owns {1}",obj.Owner,obj.getName());
Console.ReadKey();
}
}
}
Comments
Post a Comment