static void Main(string[] args) { string[] info; List <Animal> animals = new List <Animal>(); while (true) { info = Console.ReadLine().Split(' '); if (info[0] == "End") { break; } string[] food = Console.ReadLine().Split(' '); Animal animal = null; switch (info[0]) { case "Cat": animal = new Cat(info[1], Convert.ToDouble(info[2]), info[3], info[4], Convert.ToInt32(food[1])); break; case "Tiger": animal = new Tiger(info[1], Convert.ToDouble(info[2]), info[3], info[4], Convert.ToInt32(food[1])); break; case "Hen": Hen hen = new Hen(info[1], Convert.ToDouble(info[2]), Convert.ToDouble(info[3]), Convert.ToInt32(food[1])); break; case "Owl": Owl owl = new Owl(info[1], Convert.ToDouble(info[2]), Convert.ToDouble(info[3]), Convert.ToInt32(food[1])); break; case "Mouse": Mouse mouse = new Mouse(info[1], Convert.ToDouble(info[2]), info[3], Convert.ToInt32(food[1])); break; case "Dog": Dog dog = new Dog(info[1], Convert.ToDouble(info[2]), info[3], Convert.ToInt32(food[1]));; break; default: Console.WriteLine($"{info[0]} does not exist."); break; } animal.Talk(); animal.Eat(food[0], food[1]); animals.Add(animal); } foreach (var animal in animals) { Console.WriteLine(animal.ToString()); } }
static void Main(string[] args) { var animals = new List <Animal>(); while (true) { string[] animalInput = Console.ReadLine().Split(); if (animalInput[0] == "End") { break; } string[] foodInput = Console.ReadLine().Split(); Animal animal = null; Food food = null; string type = animalInput[0]; string name = animalInput[1]; double weight = double.Parse(animalInput[2]); switch (type) { case "Owl": animal = new Owl(name, weight, double.Parse(animalInput[3])); break; case "Hen": animal = new Hen(name, weight, double.Parse(animalInput[3])); break; case "Mouse": animal = new Mouse(name, weight, animalInput[3]); break; case "Dog": animal = new Dog(name, weight, animalInput[3]); break; case "Cat": animal = new Cat(name, weight, animalInput[3], animalInput[4]); break; case "Tiger": animal = new Tiger(name, weight, animalInput[3], animalInput[4]); break; default: break; } string foodType = foodInput[0]; int foodQuantity = int.Parse(foodInput[1]); switch (foodType) { case "Fruit": food = new Fruit(foodQuantity); break; case "Vegetable": food = new Vegetable(foodQuantity); break; case "Meat": food = new Meat(foodQuantity); break; case "Seeds": food = new Seeds(foodQuantity); break; default: break; } Console.WriteLine(animal.AskForFood()); animal.Feed(food); animals.Add(animal); } foreach (var animal in animals) { Console.WriteLine(animal.ToString()); } }
static void Main(string[] args) { List <Animal> animals = new List <Animal>(); while (true) { string input = Console.ReadLine(); if (input == "End") { break; } string[] currentAnimal = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); string[] currentFood = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); try { Animal animal = null; string typeOfAnimal = currentAnimal[0]; string animalName = currentAnimal[1]; double animalWeight = double.Parse(currentAnimal[2]); double wingSize; string livingRegion; string breed; switch (typeOfAnimal) { case "Hen": wingSize = double.Parse(currentAnimal[3]); animal = new Hen(animalName, animalWeight, wingSize); break; case "Owl": wingSize = double.Parse(currentAnimal[3]); animal = new Owl(animalName, animalWeight, wingSize); break; case "Dog": livingRegion = currentAnimal[3]; animal = new Dog(animalName, animalWeight, livingRegion); break; case "Mouse": livingRegion = currentAnimal[3]; animal = new Mouse(animalName, animalWeight, livingRegion); break; case "Cat": livingRegion = currentAnimal[3]; breed = currentAnimal[4]; animal = new Cat(animalName, animalWeight, livingRegion, breed); break; case "Tiger": livingRegion = currentAnimal[3]; breed = currentAnimal[4]; animal = new Tiger(animalName, animalWeight, livingRegion, breed); break; } animals.Add(animal); Food food = null; string typeOfFood = currentFood[0]; int foodQuantity = int.Parse(currentFood[1]); switch (typeOfFood) { case "Vegetable": food = new Vegetable(foodQuantity); break; case "Seeds": food = new Seeds(foodQuantity); break; case "Fruit": food = new Fruit(foodQuantity); break; case "Meat": food = new Meat(foodQuantity); break; default: break; } Console.WriteLine(animal.ProduceSound()); animal.ValidateFood(food); } catch (Exception ex) { Console.WriteLine(ex.Message); } } foreach (Animal animal in animals) { Console.WriteLine(animal.ToString()); } }