private List <IAnimal> OperateHen(string[] input, List <IAnimal> animals) { string name = input[1]; double weight = double.Parse(input[2]); Animal animal = new Hen(name, weight, double.Parse(input[3])); string[] inputFood = Console.ReadLine().Split(); Food food = CreateFood(inputFood); Console.WriteLine(animal.ProduceSound()); animal.Eat(food); animals.Add(animal); return(animals); }
public static void Main() { List <Animal> animals = new List <Animal>(); string input; while ((input = Console.ReadLine()) != "End") { var animalInfo = input.Split(); var foodInfo = Console.ReadLine().Split(); var animalType = animalInfo[0]; var animalName = animalInfo[1]; var weight = double.Parse(animalInfo[2]); var foodType = foodInfo[0]; var quantity = int.Parse(foodInfo[1]); Food food = null; switch (foodType) { case "Fruit": food = new Fruit(quantity); break; case "Meat": food = new Meat(quantity); break; case "Seeds": food = new Seeds(quantity); break; case "Vegetable": food = new Vegetable(quantity); break; default: Console.WriteLine("foodsProblem"); break; } if (animalType == "Owl" || animalType == "Hen") { var wingSize = double.Parse(animalInfo[3]); if (animalType == "Owl") { Bird owl = new Owl(animalName, weight, wingSize); Console.WriteLine(owl.ProduceSound()); owl.Eat(food, quantity); animals.Add(owl); } else if (animalType == "Hen") { Bird hen = new Hen(animalName, weight, wingSize); Console.WriteLine(hen.ProduceSound()); hen.Eat(food, quantity); animals.Add(hen); } } else if (animalType == "Mouse" || animalType == "Dog") { var livingRegion = animalInfo[3]; if (animalType == "Mouse") { Mammal mouse = new Mouse(animalName, weight, livingRegion); Console.WriteLine(mouse.ProduceSound()); mouse.Eat(food, quantity); animals.Add(mouse); } else if (animalType == "Dog") { Mammal dog = new Dog(animalName, weight, livingRegion); Console.WriteLine(dog.ProduceSound()); dog.Eat(food, quantity); animals.Add(dog); } } else if (animalType == "Cat" || animalType == "Tiger") { var livingRegion = animalInfo[3]; var breed = animalInfo[4]; if (animalType == "Cat") { Feline cat = new Cat(animalName, weight, livingRegion, breed); Console.WriteLine(cat.ProduceSound()); cat.Eat(food, quantity); animals.Add(cat); } else if (animalType == "Tiger") { Feline tiger = new Tiger(animalName, weight, livingRegion, breed); Console.WriteLine(tiger.ProduceSound()); tiger.Eat(food, quantity); animals.Add(tiger); } } } foreach (var animal in animals) { Console.WriteLine(animal.ToString()); } }
static void Main(string[] args) { List <Animal> animals = new List <Animal>(); string command; while ((command = Console.ReadLine()) != "End") { string[] animalArgs = command.Split(); string[] foodArgs = Console.ReadLine().Split(); string animal = animalArgs[0]; string name = animalArgs[1]; double weight = double.Parse(animalArgs[2]); string foodType = foodArgs[0]; int foodQuantity = int.Parse(foodArgs[1]); try { if (animal == "Hen" || animal == "Owl") { double wingSize = double.Parse(animalArgs[3]); if (animal == "Hen") { Animal hen = new Hen(name, weight, foodType, foodQuantity, wingSize); Console.WriteLine(hen.ToString()); animals.Add(hen); hen.Eat(); } else { Animal owl = new Owl(name, weight, foodType, foodQuantity, wingSize); Console.WriteLine(owl.ToString()); animals.Add(owl); owl.Eat(); } } else if (animal == "Tiger" || animal == "Cat") { string livinRedion = animalArgs[3]; string bread = animalArgs[4]; if (animal == "Tiger") { Tiger tiger = new Tiger(name, weight, foodType, livinRedion, foodQuantity, bread); Console.WriteLine(tiger.ToString()); animals.Add(tiger); tiger.Eat(); } else { Cat cat = new Cat(name, weight, foodType, livinRedion, foodQuantity, bread); Console.WriteLine(cat.ToString()); animals.Add(cat); cat.Eat(); } } else if (animal == "Mouse" || animal == "Dog") { string livingRedion = animalArgs[3]; if (animal == "Mouse") { Mouse mouse = new Mouse(name, weight, foodType, livingRedion, foodQuantity); Console.WriteLine(mouse.ToString()); animals.Add(mouse); mouse.Eat(); } else { Dog dog = new Dog(name, weight, foodType, livingRedion, foodQuantity); Console.WriteLine(dog.ToString()); animals.Add(dog); dog.Eat(); } } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } } foreach (Animal animal in animals) { if (animal is Bird) { var bird = (Bird)animal; Console.WriteLine($"{bird.GetType().Name} [{bird.Name}, {bird.WingSize}, {bird.Weight}, {bird.FoodQuantity}]"); } else if (animal is Feline) { var feline = (Feline)animal; Console.WriteLine($"{feline.GetType().Name} [{feline.Name}, {feline.Bread}, {feline.Weight}, {feline.LivingRegion}, {feline.FoodQuantity}]"); } else { var mimmal = (Mammal)animal; Console.WriteLine($"{mimmal.GetType().Name} [{mimmal.Name}, {mimmal.Weight}, {mimmal.LivingRegion}, {mimmal.FoodQuantity}]"); } } }
static void Main(string[] args) { List <Animal> animals = new List <Animal>(); string inputAnimal; while ((inputAnimal = Console.ReadLine()) != "End") { string[] dataAnimal = inputAnimal.Split(' ', StringSplitOptions.RemoveEmptyEntries); string[] dataFood = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); switch (dataAnimal[0]) { case "Owl": Owl owl = new Owl(dataAnimal[1], double.Parse(dataAnimal[2]), double.Parse(dataAnimal[3])); Console.WriteLine(owl.AskForFood()); owl.Eat(dataFood[0], int.Parse(dataFood[1])); animals.Add(owl); break; case "Hen": Hen hen = new Hen(dataAnimal[1], double.Parse(dataAnimal[2]), double.Parse(dataAnimal[3])); Console.WriteLine(hen.AskForFood()); hen.Eat(dataFood[0], int.Parse(dataFood[1])); animals.Add(hen); break; case "Mouse": Mouse mouse = new Mouse(dataAnimal[1], double.Parse(dataAnimal[2]), dataAnimal[3]); Console.WriteLine(mouse.AskForFood()); mouse.Eat(dataFood[0], int.Parse(dataFood[1])); animals.Add(mouse); break; case "Dog": Dog dog = new Dog(dataAnimal[1], double.Parse(dataAnimal[2]), dataAnimal[3]); Console.WriteLine(dog.AskForFood()); dog.Eat(dataFood[0], int.Parse(dataFood[1])); animals.Add(dog); break; case "Cat": Cat cat = new Cat(dataAnimal[1], double.Parse(dataAnimal[2]), dataAnimal[3], dataAnimal[4]); Console.WriteLine(cat.AskForFood()); cat.Eat(dataFood[0], int.Parse(dataFood[1])); animals.Add(cat); break; case "Tiger": Tiger tiger = new Tiger(dataAnimal[1], double.Parse(dataAnimal[2]), dataAnimal[3], dataAnimal[4]); Console.WriteLine(tiger.AskForFood()); tiger.Eat(dataFood[0], int.Parse(dataFood[1])); animals.Add(tiger); break; } } foreach (var animal in animals) { Console.WriteLine(animal); } }
public static void Main() { var animals = new List <Animal>(); string input; while ((input = Console.ReadLine()) != "End") { var animalInfo = input.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); var foodInfo = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); var animalType = animalInfo[0]; var foodType = foodInfo[0]; var foodQuantity = int.Parse(foodInfo[1]); if (animalType == "Hen") { var hen = new Hen(animalInfo[1], double.Parse(animalInfo[2]), double.Parse(animalInfo[3])); hen.ProduceSound(); hen.Eat(foodQuantity); animals.Add(hen); } else if (animalType == "Mouse") { var mouse = new Mouse(animalInfo[1], double.Parse(animalInfo[2]), animalInfo[3]); mouse.ProduceSound(); if (mouse.FavouriteFood.Contains(foodType)) { mouse.Eat(foodQuantity); } else { NotFavouriteFood(animalType, foodType); } animals.Add(mouse); } else if (animalType == "Cat") { var cat = new Cat(animalInfo[1], double.Parse(animalInfo[2]), animalInfo[3], animalInfo[4]); cat.ProduceSound(); if (cat.FavouriteFood.Contains(foodType)) { cat.Eat(foodQuantity); } else { NotFavouriteFood(animalType, foodType); } animals.Add(cat); } else if (animalType == "Tiger") { var tiger = new Tiger(animalInfo[1], double.Parse(animalInfo[2]), animalInfo[3], animalInfo[4]); tiger.ProduceSound(); if (tiger.FavouriteFood.Contains(foodType)) { tiger.Eat(foodQuantity); } else { NotFavouriteFood(animalType, foodType); } animals.Add(tiger); } else if (animalType == "Dog") { var dog = new Dog(animalInfo[1], double.Parse(animalInfo[2]), animalInfo[3]); dog.ProduceSound(); if (dog.FavouriteFood.Contains(foodType)) { dog.Eat(foodQuantity); } else { NotFavouriteFood(animalType, foodType); } animals.Add(dog); } else if (animalType == "Owl") { var owl = new Owl(animalInfo[1], double.Parse(animalInfo[2]), double.Parse(animalInfo[3])); owl.ProduceSound(); if (owl.FavouriteFood.Contains(foodType)) { owl.Eat(foodQuantity); } else { NotFavouriteFood(animalType, foodType); } animals.Add(owl); } } foreach (var animal in animals) { Console.WriteLine(animal); } }