static void Main(string[] args) { FoodFactory foodFactory = new FoodFactory(); AnimalFactory animalFactory = new AnimalFactory(); List <Animal> animals = new List <Animal>(); string input = Console.ReadLine(); while (input != "End") { string[] animalArgs = input .Split(); string[] foodArgs = Console.ReadLine() .Split(); string foodType = foodArgs[0]; int foodWeight = int.Parse(foodArgs[1]); Food food = foodFactory.Create(foodType, foodWeight); Animal animal = animalFactory.Create(animalArgs); Console.WriteLine(animal.ProduceSound()); try { animal.Eat(foodType, foodWeight); } catch (Exception ex) { Console.WriteLine(ex.Message); } animals.Add(animal); input = Console.ReadLine(); } foreach (var animal in animals) { Console.WriteLine(animal); } }
static void Main(string[] args) { List <Animal> animals = new List <Animal>(); while (true) { string line = Console.ReadLine(); if (line == "End") { break; } string[] animalArgs = line.Split(); Animal animal = AnimalFactory.Create(animalArgs); string[] foodArgs = Console.ReadLine().Split(); Food food = FoodFactory.Create(foodArgs); Console.WriteLine(animal.ProduceSound()); try { animal.Eat(food); } catch (Exception ex) { Console.WriteLine(ex.Message); } animals.Add(animal); } foreach (var animal in animals) { Console.WriteLine(animal); } }
public static void Main() { string input = Console.ReadLine(); List <Animal> animals = new List <Animal>(); while (input != "End") { string[] animalArgs = input .Split(); Animal animal = AnimalFactory.Create(animalArgs); string[] foodArgs = Console.ReadLine() .Split(); Food food = FoodFactory.Create(foodArgs); Console.WriteLine(animal.ProduceSound()); try { animal.Eat(food); } catch (Exception ex) { Console.WriteLine(ex.Message); } animals.Add(animal); input = Console.ReadLine(); } foreach (var animal in animals) { Console.WriteLine(animal); } }