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); }
private static void CreateBird(string[] splitInput) { string name = splitInput[1]; double weight = double.Parse(splitInput[2]); double wingSize = double.Parse(splitInput[3]); switch (splitInput[0].ToLower()) { case "hen": Hen hen = new Hen(name, weight, 0, wingSize); animals.Add(hen); hen.ProduceSound(); break; case "owl": Owl owl = new Owl(name, weight, 0, wingSize); animals.Add(owl); owl.ProduceSound(); break; } }
private static void ReadAddAndTryToFeedAnimal(List <Animal> animals, string command) { string[] commTokens = command.Split(); string animalType = commTokens[0]; string name = commTokens[1]; double weight = double.Parse(commTokens[2]); switch (animalType) { case "Owl": double owlWingSize = double.Parse(commTokens[3]); Animal newOwl = new Owl(name, weight, owlWingSize); Console.WriteLine(newOwl.ProduceSound()); TryToFeedAnimal(newOwl, animalType); animals.Add(newOwl); break; case "Hen": double henWingSize = double.Parse(commTokens[3]); Animal newHen = new Hen(name, weight, henWingSize); Console.WriteLine(newHen.ProduceSound()); TryToFeedAnimal(newHen, animalType); animals.Add(newHen); break; case "Mouse": string mouseLivingRegion = commTokens[3]; Animal newMouse = new Mouse(name, weight, mouseLivingRegion); Console.WriteLine(newMouse.ProduceSound()); TryToFeedAnimal(newMouse, animalType); animals.Add(newMouse); break; case "Dog": string dogLivingRegion = commTokens[3]; Animal newDog = new Dog(name, weight, dogLivingRegion); Console.WriteLine(newDog.ProduceSound()); TryToFeedAnimal(newDog, animalType); animals.Add(newDog); break; case "Cat": string catLivingRegion = commTokens[3]; string catBreed = commTokens[4]; Animal newCat = new Cat(name, weight, catLivingRegion, catBreed); Console.WriteLine(newCat.ProduceSound()); TryToFeedAnimal(newCat, animalType); animals.Add(newCat); break; case "Tiger": string tigerLivingRegion = commTokens[3]; string tigerBreed = commTokens[4]; Animal newTiger = new Tiger(name, weight, tigerLivingRegion, tigerBreed); Console.WriteLine(newTiger.ProduceSound()); TryToFeedAnimal(newTiger, animalType); animals.Add(newTiger); break; default: break; } }
static void Main(string[] args) { List <Animal> animals = new List <Animal>(); Animal animal = new Animal(); var input = string.Empty; while ((input = Console.ReadLine()) != "End") { var animalTokens = input.Split(' ').ToList(); var animalType = animalTokens[0]; switch (animalType) { case "Hen": animal = new Hen(animalTokens[1], double.Parse(animalTokens[2]), double.Parse(animalTokens[3])); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); break; case "Owl": animal = new Owl(animalTokens[1], double.Parse(animalTokens[2]), double.Parse(animalTokens[3])); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); break; case "Mouse": animal = new Mouse(animalTokens[1], double.Parse(animalTokens[2]), animalTokens[3]); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); break; case "Cat": animal = new Cat(animalTokens[1], double.Parse(animalTokens[2]), animalTokens[3], animalTokens[4]); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); break; case "Dog": animal = new Dog(animalTokens[1], double.Parse(animalTokens[2]), animalTokens[3]); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); break; case "Tiger": animal = new Tiger(animalTokens[1], double.Parse(animalTokens[2]), animalTokens[3], animalTokens[4]); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); break; default: break; } var feedAnimals = Console.ReadLine().Split(' ').ToList(); var food = feedAnimals[0]; var quantity = int.Parse(feedAnimals[1]); animal.IncreaseWeigth(food, quantity); } foreach (var anim in animals) { Console.WriteLine(anim); } }
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()); } }
private static void FillAnimals(string command, List <Animal> animals) { var tokens = command.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); var foodTokens = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); var typeFood = foodTokens[0]; var quantity = int.Parse(foodTokens[1]); Food food = null; switch (typeFood) { case "Vegetable": food = new Vegetable(quantity); break; case "Fruit": food = new Fruit(quantity); break; case "Meat": food = new Meat(quantity); break; case "Seeds": food = new Seeds(quantity); break; } if (tokens.Length == 5) { try { switch (tokens[0]) { case "Cat": var cat = new Cat(tokens[1], double.Parse(tokens[2]), 0, tokens[3], tokens[4]); cat.ProduceSound(); animals.Add(cat); if (cat.IsEaten(food)) { cat.EatFood(quantity); } break; case "Tiger": var tiger = new Tiger(tokens[1], double.Parse(tokens[2]), 0, tokens[3], tokens[4]); tiger.ProduceSound(); animals.Add(tiger); if (tiger.IsEaten(food)) { tiger.EatFood(quantity); } break; } } catch (Exception e) { Console.WriteLine(e.Message); } } else if (tokens.Length == 4) { try { switch (tokens[0]) { case "Mouse": var mouse = new Mouse(tokens[1], double.Parse(tokens[2]), 0, tokens[3]); mouse.ProduceSound(); animals.Add(mouse); if (mouse.IsEaten(food)) { mouse.EatFood(quantity); } break; case "Dog": var dog = new Dog(tokens[1], double.Parse(tokens[2]), 0, tokens[3]); dog.ProduceSound(); animals.Add(dog); if (dog.IsEaten(food)) { dog.EatFood(quantity); } break; case "Hen": var hen = new Hen(tokens[1], double.Parse(tokens[2]), 0, double.Parse(tokens[3])); hen.ProduceSound(); animals.Add(hen); if (hen.IsEaten(food)) { hen.EatFood(quantity); } break; case "Owl": var owl = new Owl(tokens[1], double.Parse(tokens[2]), 0, double.Parse(tokens[3])); owl.ProduceSound(); animals.Add(owl); if (owl.IsEaten(food)) { owl.EatFood(quantity); } break; } } catch (Exception e) { Console.WriteLine(e.Message); } } }
static void Main() { var animals = new List <Animal>(); string animalArgs = string.Empty; while ((animalArgs = Console.ReadLine()) != "End") { var args = animalArgs.Split(); var animalType = args[0]; Animal animal; var feeding = Console.ReadLine().Split(); var foodType = feeding[0]; var quantity = int.Parse(feeding[1]); try { switch (animalType) { case "Cat": animal = new Cat(args[1], double.Parse(args[2]), args[3], args[4]); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); animal.EatFood(foodType, quantity); break; case "Tiger": animal = new Tiger(args[1], double.Parse(args[2]), args[3], args[4]); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); animal.EatFood(foodType, quantity); break; case "Owl": animal = new Owl(args[1], double.Parse(args[2]), double.Parse(args[3])); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); animal.EatFood(foodType, quantity); break; case "Hen": animal = new Hen(args[1], double.Parse(args[2]), double.Parse(args[3])); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); animal.EatFood(foodType, quantity); break; case "Mouse": animal = new Mouse(args[1], double.Parse(args[2]), args[3]); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); animal.EatFood(foodType, quantity); break; case "Dog": animal = new Dog(args[1], double.Parse(args[2]), args[3]); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); animal.EatFood(foodType, quantity); break; default: break; } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } animals.ForEach(a => Console.WriteLine(a)); }
static void Main(string[] args) { var commands = Console.ReadLine(); var animals = new List <Animal>(); int counter = 0; while (commands != "End") { var info = commands.Split(); if (counter % 2 == 0) { switch (info[0]) { case "Hen": var hen = new Hen(info[1], double.Parse(info[2]), double.Parse(info[3])); var henFood = Console.ReadLine().Split(); Console.WriteLine(hen.ProduceSound()); hen.Weight += double.Parse(henFood[1]) * 0.35; hen.FoodEaten += int.Parse(henFood[1]); animals.Add(hen); break; case "Owl": var owl = new Owl(info[1], double.Parse(info[2]), double.Parse(info[3])); var owlFood = Console.ReadLine().Split(); Console.WriteLine(owl.ProduceSound()); if (owlFood[0] == "Meat") { owl.Weight += double.Parse(owlFood[1]) * 0.25; owl.FoodEaten += int.Parse(owlFood[1]); } else { Console.WriteLine($"Owl does not eat {owlFood[0]}!"); } animals.Add(owl); break; case "Mouse": var mouse = new Mouse(info[1], double.Parse(info[2]), info[3]); var mouseFood = Console.ReadLine().Split(); Console.WriteLine(mouse.ProduceSound()); if (mouseFood[0] == "Vegetable" || mouseFood[0] == "Fruit") { mouse.Weight += double.Parse(mouseFood[1]) * 0.10; mouse.FoodEaten += int.Parse(mouseFood[1]); } else { Console.WriteLine($"Mouse does not eat {mouseFood[0]}!"); } animals.Add(mouse); break; case "Cat": var cat = new Cat(info[1], double.Parse(info[2]), info[3], info[4]); var catFood = Console.ReadLine().Split(); Console.WriteLine(cat.ProduceSound()); if (catFood[0] == "Vegetable" || catFood[0] == "Meat") { cat.Weight += double.Parse(catFood[1]) * 0.30; cat.FoodEaten += int.Parse(catFood[1]); } else { Console.WriteLine($"Cat does not eat {catFood[0]}!"); } animals.Add(cat); break; case "Dog": var dog = new Dog(info[1], double.Parse(info[2]), info[3]); var dogFood = Console.ReadLine().Split(); Console.WriteLine(dog.ProduceSound()); if (dogFood[0] == "Meat") { dog.Weight += double.Parse(dogFood[1]) * 0.40; dog.FoodEaten += int.Parse(dogFood[1]); } else { Console.WriteLine($"Dog does not eat {dogFood[0]}!"); } animals.Add(dog); break; case "Tiger": var tiger = new Tiger(info[1], double.Parse(info[2]), info[3], info[4]); var tigerFood = Console.ReadLine().Split(); Console.WriteLine(tiger.ProduceSound()); if (tigerFood[0] == "Meat") { tiger.Weight += double.Parse(tigerFood[1]) * 1.00; tiger.FoodEaten += int.Parse(tigerFood[1]); } else { Console.WriteLine($"Tiger does not eat {tigerFood[0]}!"); } animals.Add(tiger); break; } } counter++; if (counter % 2 == 0) { commands = Console.ReadLine(); } } foreach (var an in animals) { Console.WriteLine(an); } }
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); } }