2016-10-09 3 views
-3
namespace HelloDogs 

{ класса Dog { частной строка barkSound; частная струнная порода; // Добавлен dogHeight, dogColor и noOfLegs к
private int dogHeight; // приватная переменная приватная строка dogColor; private static int noOfLegs;Как я называю статическим из класса, я создал в C#

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 ниже, чтобы отобразить все подробности о публичных строках собаки 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; 

    } 


} 

}

+1

Сдача кодов не ставит хороший вопрос. Чтобы получить помощь, сделайте крошечный пример и задайте очень конкретный вопрос. – dasblinkenlight

+0

ОК спасибо, я буду очень конкретным в следующий раз, и я сделаю свой пример крошечным для быстрого понимания – kelvin

ответ

Смежные вопросы