static void Main(string[] args) { var reptile = new Reptile("Crocodile"); var reptile1 = new Reptile("frog"); var mammal = new Mammal("Goat"); var bird = new Bird("Parrot"); Console.WriteLine("Who want a baby?"); Console.WriteLine(reptile.GetName() + ", " + reptile.WantChild()); Console.WriteLine(mammal.GetName() + ", " + mammal.WantChild()); Console.WriteLine(bird.GetName() + ", " + bird.WantChild()); Console.WriteLine(reptile1.GetName() + ", " + reptile1.WantChild()); Console.ReadLine(); }
static void Main(string[] args) { List <Animal> animalList = new List <Animal>(); animalList.Add(new Animal(true, 12, 200)); animalList.Add(new Mammal(false, 5, 55, 38, 2)); animalList.Add(new Bear(true, 10, 300, 4, 3, 12.3, "George.")); animalList.Add(new Giraffe(true, 2, 435, 45, 1, 7.3)); foreach (Animal a in animalList) { if (a.GetType() == typeof(Mammal)) { Console.WriteLine("----------"); Mammal m = (Mammal)a; Console.WriteLine(m.ToString()); Console.WriteLine("This mammal has " + m.ChildrenInWomb + " children."); Console.Write(Environment.NewLine); } if (a.GetType() == typeof(Bear)) { Console.Write(Environment.NewLine); Bear b = (Bear)a; Console.WriteLine(b.ToString()); Console.WriteLine("Bear is asking to eat. Write 'y' for yes or 'n' for no."); if (Console.ReadKey(true).Key == ConsoleKey.Y) { b.EatMeat(); } if (Console.ReadKey(true).Key == ConsoleKey.N) { Console.WriteLine("You heartless bear murderer!!"); } b.EatMeat(); b.EatMeat(); b.EatMeat(); } } Console.ReadKey(); }