namespace HelloDogs
{
班狗
{
私人字符串barkSound;
私人品种; //将dogHeight,dogColor和noOfLegs添加到
私人int dogHeight; //私有变量
私人字符串dogColor;
private static int noOfLegs;
public string Breed
{
get { return breed; }
set { breed = value; }
}
public static int NoOfLegs
{
get{return noOfLegs; } // I created properties to encapsulate the variables
set {noOfLegs = value; } // dogHeight, dogColor and noOfLegs using the properties
}
public int DogHeight
{
get {return dogHeight;}
set{dogHeight = value;}
}
public string DogColor
{
get {return dogColor;}
set{ dogColor = value;}
}
private string dogSpeech;
public Dog()
{
barkSound = "Jack!";
breed = "cocker spaniel";
}
// Added a new constructor below that takes the following parameters
public Dog(int h,string b, string c )
{
dogHeight = h;
dogColor = c;
breed = b;
}
// A private method to check the dogHeight if true or false
private bool IsBig(int x)
{
if (x < 50)
return false;
else
return true;
}
//更改下面的GetSpeech方法以显示有关狗的所有详细信息
public string GetSpeech()
{
dogSpeech = "Hello, I am a " + breed + " , " + dogHeight + "cm" + ","
+ dogColor + "." + barkSound ;
return dogSpeech;
if(IsBig(dogHeight))
{
return dogSpeech = "You are big ";
} else
{
dogSpeech = " You are not big enough";
}
}
public void SetSound(String barkSound)
{
this.barkSound = barkSound;
}
}
}