示例#1
0
 // Copy constructor.
 public AnimalFarm(AnimalFarm AnimalFarmObject)
 {
     this.name  = AnimalFarmObject.name;
     this.voice = AnimalFarmObject.voice;
     this.type  = AnimalFarmObject.type;
     this.food  = AnimalFarmObject.food;
 }
示例#2
0
        static void Main(string[] args)
        {
            //		********************************************Four instances********************************************

            Console.WriteLine("********************************************Four instances********************************************");

            AnimalFarm Pig = new AnimalFarm("Miss Piggy", "Oinks", "Pig", "Vegetables and Fruits");

            Console.WriteLine(Pig.speak());
            Console.WriteLine(Pig.eat());
            Pig.printAnimalInformation();

            AnimalFarm Sheep = new AnimalFarm("Mr. Sh", "Bleats", "Sheep", "Grass");

            Console.WriteLine(Sheep.speak());
            Console.WriteLine(Sheep.eat());
            Sheep.printAnimalInformation();

            AnimalFarm Cow = new AnimalFarm("Miss Cow", "Moos", "Cow", "Grass and Vegetables");

            Console.WriteLine(Cow.speak());
            Console.WriteLine(Cow.eat());
            Cow.printAnimalInformation();

            AnimalFarm Goat = new AnimalFarm("Mr. Go", "Bleats", "Goat", "Grass and Fruits");

            Console.WriteLine(Goat.speak());
            Console.WriteLine(Goat.eat());
            Goat.printAnimalInformation();

            //		********************************************Four classes, Four instances********************************************

            Console.WriteLine("\n\n********************************************Four classes, Four instances********************************************\n");

            Horse horse = new Horse();

            horse.Type  = "Horse";
            horse.Name  = "Mr. Ed";
            horse.Food  = "Grass";
            horse.Voice = "Neigh";
            Console.WriteLine(horse.speak());
            Console.WriteLine(horse.eat());
            horse.printAnimalInformation();

            Sheep sheep = new Sheep();

            sheep.Type  = "Sheep";
            sheep.Name  = "Mr. Sh";
            sheep.Food  = "Grass";
            sheep.Voice = "Bleats";
            Console.WriteLine(sheep.speak());
            Console.WriteLine(sheep.eat());
            sheep.printAnimalInformation();

            Cow cow = new Cow();

            cow.Type  = "Cow";
            cow.Name  = "Miss Cow";
            cow.Food  = "Grass and Vegetables";
            cow.Voice = "Moos";
            Console.WriteLine(cow.speak());
            Console.WriteLine(cow.eat());
            cow.printAnimalInformation();

            Goat goat = new Goat();

            goat.Type  = "Goat";
            goat.Name  = "Mr. Go";
            goat.Food  = "Grass and Fruits";
            goat.Voice = "Bleats";
            Console.WriteLine(goat.speak());
            Console.WriteLine(goat.eat());
            goat.printAnimalInformation();


            Console.ReadLine();
        }