public void Run() { while (true) { string[] animalArgs = Console.ReadLine().Split(); if (animalArgs[0] == "End") { break; } string[] foodArgs = Console.ReadLine().Split(); IAnimal animal = ProduceAnimal(animalArgs); IFood food = this.foodFactory.ProduceFood(foodArgs[0], int.Parse(foodArgs[1])); this.animals.Add(animal); Console.WriteLine(animal.ProduceSount()); try { animal.Feed(food); } catch (UneatableFoodException ufe) { Console.WriteLine(ufe.Message); } } PrintOutput(); }
public void Run() { string command = Console.ReadLine(); while (command != "End") { string foodInput = Console.ReadLine(); IAnimal animal = GetAnimal(command); IFood food = GetFood(foodInput); Console.WriteLine(animal.AskFood()); try { animal.Feed(food); } catch (InvalidOperationException ioe) { Console.WriteLine(ioe.Message); } command = Console.ReadLine(); } PrintOutput(); }
public void Run() { string command; while ((command = Console.ReadLine()) != "End") { string[] animalArgs = command.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); string[] foodArgs = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); IAnimal animal = CreateAnimal(animalArgs); IFood food = foodFactory.ProduceFood(foodArgs[0], int.Parse(foodArgs[1])); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); try { animal.Feed(food); } catch (UneatableFoodException ufe) { Console.WriteLine(ufe.Message); } } foreach (var animal in animals) { Console.WriteLine(animal); } }
public void Run() { string comand; while ((comand = Console.ReadLine()) != "End") { string[] animalArgs = comand.Split(' ', StringSplitOptions.RemoveEmptyEntries); string[] foodArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); string animalType = animalArgs[0]; string name = animalArgs[1]; double weight = double.Parse(animalArgs[2]); IAnimal animal = ProduceAnimal(animalArgs, animalType, name, weight); IFood food = ProduceFood(foodArgs); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); try { animal.Feed(food); } catch (UnEatableFoodException ufe) { Console.WriteLine(ufe.Message); } } foreach (IAnimal animal1 in animals) { Console.WriteLine(animal1); } }
public void Run() { string cmd; while ((cmd = Console.ReadLine()) != "End") { var animalArgs = cmd.Split(); var foodArgs = Console.ReadLine().Split(); var animalType = animalArgs[0]; var name = animalArgs[1]; var weight = double.Parse(animalArgs[2]); IAnimal animal = ProduseAnimal(animalArgs, animalType, name, weight); IFood food = this.foodFactory.ProduceFood(foodArgs[0], int.Parse(foodArgs[1])); this.animals.Add(animal); Console.WriteLine(animal.ProduseSund()); try { animal.Feed(food); } catch (UneatableFoodException ufe) { Console.WriteLine(ufe.Message); } } foreach (var item in this.animals) { Console.WriteLine(item); } }
public void Run() { while (true) { string input = Console.ReadLine(); if (input == "End") { break; } IAnimal animal = ProduceAnimal(input); Food food = ProduceFood(); try { this.animals.Add(animal); Console.WriteLine(animal.ProduceSound()); animal.Feed(food); } catch (NotValidFoodException ex) { string message = String.Format(ex.Message, animal.GetType().Name, food.GetType().Name); Console.WriteLine(message); } } foreach (var animal in this.animals) { Console.WriteLine(animal); } }
public void Run() { string command; while ((command = Console.ReadLine()) != "End") { string[] animalArgs = command.Split(); IAnimal animal = ProduceAnimal(animalArgs); string[] foodArgs = Console.ReadLine().Split(); string foodName = foodArgs[0]; int quantity = int.Parse(foodArgs[1]); IFood food = this.foodFactory.ProduceFood(foodName, quantity); Console.WriteLine(animal.ProduceSound()); try { animal.Feed(food); } catch (UneatableFoodExceptions ufe) { Console.WriteLine(ufe.Message); } this.animals.Add(animal); } foreach (var animal in this.animals) { Console.WriteLine(animal); } }
public void Run() { while (true) { var animalArgs = Console.ReadLine().Split(); if (animalArgs[0] == "End") { break; } var foodArgs = Console.ReadLine().Split(); var foodType = foodArgs[0]; var foodQuantity = int.Parse(foodArgs[1]); IAnimal animal = ProduceAnimal(animalArgs); IFood food = this.foodFactory.ProduceFood(foodType, foodQuantity); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); try { animal.Feed(food); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); continue; } } Console.WriteLine(string.Join(Environment.NewLine, this.animals)); }
internal static void WorkWithAnimal(IAnimal zver) { //throw new NotImplementedException(); zver.Hello(); zver.Feed(); zver.Play(); zver.Wash(); zver.Voice(); Console.WriteLine("\n ******** \n"); Console.ReadLine(); }
public void Run() { int numOfInput = 0; IAnimal lastAnimal = null; IFood lastFood = null; string command; while ((command = this.reader.ReadLine()) != "End") { string[] curInput = command.Split(); try { if (numOfInput % 2 == 0) { IAnimal animal = this.animalCreator.CreateAnimal(curInput); this.animals.Add(animal); lastAnimal = animal; } else { IFood food = this.foodCreator.CreateFood(curInput); lastFood = food; } } catch (ArgumentException e) { this.writer.WriteLine(e.Message); } if (numOfInput % 2 != 0) { this.writer.WriteLine(lastAnimal.ProduceSound()); try { lastAnimal.Feed(lastFood); } catch (ArgumentException e) { this.writer.WriteLine(e.Message); } } numOfInput++; } foreach (IAnimal animal in animals) { this.writer.WriteLine(animal.ToString()); } }
public void Run() { string command = Console.ReadLine(); while (command != "End") { string[] animalInformation = command .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); string[] foodInformation = Console.ReadLine() .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); IAnimal animal = ProduceAnimal(animalInformation); string foodType = foodInformation[0]; int foodQuantity = int.Parse(foodInformation[1]); IFood food = this.foodFactory.ProduceFood(foodType, foodQuantity); Console.WriteLine(animal.ProduceSound()); this.animals.Add(animal); try { animal.Feed(food); } catch (UneateableFoodException ufe) { Console.WriteLine(ufe.Message); } command = Console.ReadLine(); } foreach (var animal in this.animals) { Console.WriteLine(animal); } }
public void Run() { string command; while ((command = Console.ReadLine()) != "End") { string[] animalArgs = command .Split(' ', StringSplitOptions.RemoveEmptyEntries) .ToArray(); string[] foodArgs = Console.ReadLine() .Split(' ', StringSplitOptions.RemoveEmptyEntries) .ToArray(); IAnimal animal = ProduceAnimal(animalArgs); animals.Add(animal); string foodType = foodArgs[0]; int foodQuantity = int.Parse(foodArgs[1]); IFood food = this.foodFactory.ProduceFood(foodType, foodQuantity); Console.WriteLine(animal.ProduceSound()); try { animal.Feed(food); } catch (FoodException ex) { Console.WriteLine(ex.Message); } } foreach (IAnimal animal in this.animals) { Console.WriteLine(animal); } }