{/*Створити суперклас Птах і підкласи Орел, Папуга, Нелітаючий птах, Страус, Пінгвін. * За допомогою конструктора задати вік кожного птаха. * Визначити максимальну висоту польоту літаючих птахів та швидкість бігу нелітаючих.*/ static void Main(string[] args) { Eagle eagle = new Eagle(100, 10, true); Parrot parrot = new Parrot(40, 4, true); Pinguin pinguin = new Pinguin(60, 30, false); Straus straus = new Straus(120, 42, false); eagle.Born(); eagle.Move(); eagle.StopMoving(); eagle.Die(); Console.WriteLine(eagle.GetInfo()); Console.WriteLine(new string('-', 30)); parrot.Born(); parrot.Move(); parrot.StopMoving(); parrot.Die(); Console.WriteLine(parrot.GetInfo()); Console.WriteLine(new string('-', 30)); pinguin.Born(); pinguin.Move(); pinguin.StopMoving(); pinguin.Die(); Console.WriteLine(pinguin.GetInfo()); Console.WriteLine(new string('-', 30)); straus.Born(); straus.Move(); straus.StopMoving(); straus.Die(); Console.WriteLine(straus.GetInfo()); Console.WriteLine(new string('-', 30)); }
/// <summary> /// Creates aniamls for the factory. /// </summary> /// <param name="type"> The type of animal that will be created.</param> /// <param name="name"> The name of the animal.</param> /// <param name="age"> The age of the animal.</param> /// <param name="weight"> The weight of the animal.</param> /// <param name="gender"> The gender of the animal.</param> public static Animal CreateAnimal(AnimalType type, string name, int age, double weight, Gender gender) { Animal result = null; switch (type) { case AnimalType.Chimpanzee: result = new Chimpanzee(name, age, weight, gender); break; case AnimalType.Dingo: result = new Dingo(name, age, weight, gender); break; case AnimalType.Eagle: result = new Eagle(name, age, weight, gender); break; case AnimalType.Hummingbird: result = new Hummingbird(name, age, weight, gender); break; case AnimalType.Kangaroo: result = new Kangaroo(name, age, weight, gender); break; case AnimalType.Ostrich: result = new Ostrich(name, age, weight, gender); break; case AnimalType.Platypus: result = new Platypus(name, age, weight, gender); break; case AnimalType.Shark: result = new Shark(name, age, weight, gender); break; case AnimalType.Squirrel: result = new Squirrel(name, age, weight, gender); break; default: break; } return(result); }
static void Main(string[] args) { Eagle eagle = new Eagle("Val", AnimalCategories.bird); Console.WriteLine(eagle); eagle.Swim(); eagle.Fly(); eagle.Move(); eagle.Walk(); Console.WriteLine("--------------------------------------------"); Platypus platypus = new Platypus("Orni", AnimalCategories.mammal); Console.WriteLine(platypus); platypus.Move(); platypus.Swim(); platypus.Walk(); Console.WriteLine("---------------------------------------------"); WildDuck wildDuck = new WildDuck("Donald", AnimalCategories.bird); Console.WriteLine(wildDuck); wildDuck.Fly(); wildDuck.Move(); wildDuck.Swim(); wildDuck.Walk(); Console.WriteLine("----------------------------------------------"); Crocodile aligator = new Crocodile("Aligator", AnimalCategories.reptile); Console.WriteLine(aligator); aligator.Crawl(); aligator.Move(); aligator.Swim(); aligator.Walk(); }
/// <summary> /// Creates an animal. /// </summary> /// <param name="type">The type of animal.</param> /// <param name="name">The name of the animal.</param> /// <param name="age">The age of the animal.</param> /// <param name="weight">The weight of the animal.</param> /// <param name="gender">The gender of the animal.</param> /// <returns>Returns an animal.</returns> public static Animal CreateAnimal(AnimalType type, string name, int age, double weight, Gender gender) { Animal animal = null; switch (type) { case AnimalType.Chimpanzee: // Create Chewy the chimpanzee. animal = new Chimpanzee(name, age, weight, gender); break; case AnimalType.Dingo: // Create Dolly the dingo. animal = new Dingo(name, age, weight, gender); // Create Dixie the dingo. animal = new Dingo(name, age, weight, gender); break; case AnimalType.Eagle: // Create Edgar the eagle.. animal = new Eagle(name, age, weight, gender); break; case AnimalType.Hummingbird: // Create Harold. animal = new Hummingbird(name, age, weight, gender); break; case AnimalType.Kangaroo: // Create Khan the kangaroo. animal = new Kangaroo(name, age, weight, gender); break; case AnimalType.Ostrich: // Create Ozzie the ostrich. animal = new Ostrich(name, age, weight, gender); break; case AnimalType.Platypus: // Create Patty. animal = new Platypus(name, age, weight, gender); break; case AnimalType.Shark: // Creates Sasha the shark. animal = new Shark(name, age, weight, gender); break; case AnimalType.Squirrel: // Create Sonny the squirrel. animal = new Squirrel(name, age, weight, gender); break; } return(animal); }