static void Main(string[] args) { IAnimal animal = GetAnimal(); animal.Eat(); animal.Move(); }
public void Run() { string command = Console.ReadLine(); while (command != "End") { string[] animalInfo = command .Split(" ", StringSplitOptions.RemoveEmptyEntries); string[] foodInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); IAnimal animal = this.CreateAnimal(animalInfo); this.animals.Add(animal); Console.WriteLine(animal.ProduceASound()); IFood food = this.CreateFood(foodInfo); try { animal.Eat(food); } catch (InvalidOperationException ioe) { Console.WriteLine(ioe.Message); } command = Console.ReadLine(); } PrintAnimals(); }
public void Run() { var animals = new List <IAnimal>(); string input; while ((input = Console.ReadLine()) != "End") { var animalTokens = input.Split(); var foodTokens = Console.ReadLine().Split(); IAnimal animal = CreateAnimal(animalTokens); IFood food = CreateFood(foodTokens); Console.WriteLine(animal.ProduceSound()); try { animal.Eat(food, food.Quantity); } catch (Exception e) { Console.WriteLine(e.Message); } animals.Add(animal); } animals.ForEach(a => Console.WriteLine(a)); }
static void Main() { List <IAnimal> animals = new List <IAnimal>(); string input = Console.ReadLine(); while (input != "End") { string[] animalTokens = input.Split(); string[] foodTokens = Console.ReadLine().Split(); IAnimal animal = AnimalFactory.CreateAnimal(animalTokens); IFood food = FoodFactory.CreateFood(foodTokens); Console.WriteLine(animal.AskForFood()); try { animal.Eat(food, food.Quantity); } catch (Exception ex) { Console.WriteLine(ex.Message); } animals.Add(animal); input = Console.ReadLine(); } animals.ForEach(x => Console.WriteLine(x)); }
public void Run() { string input; while ((input = Read()) != "End") { try { IAnimal animal = animalFactory.CreateAnimal(input.Split()); IFood food = foodFactory.CreateFood(Read().Split()); animals.Add(animal); Print(animal.AskFood()); animal.Eat(food); } catch (ArgumentException ae) { Print(ae.Message); } } animals.ForEach(a => Print(a.ToString())); }
public void Run() { while (true) { string command = Console.ReadLine(); if (command == "End") { break; } string[] animalArgs = command.Split(); animal = animalFactory.ProduceAnimal(animalArgs); string[] foodArgs = Console.ReadLine().Split(); food = foodFactory.ProduceFood(foodArgs); animals.Add(animal); animal.ProduseSound(); animal.Eat(food); } foreach (var currAnimal in animals) { Console.WriteLine(currAnimal); } }
public void Run() { string command; while ((command = this.reader.ReadLine()) != "End") { IAnimal animal = CreateAnimal(command); IFood food = CreateFood(); this.writer.WriteLine(animal.ProduceSound()); try { animal.Eat(food); } catch (InvalidFoodTypeException ifte) { this.writer.WriteLine(ifte.Message); } animals.Add(animal); } PrintOutput(); }
public void Run() { string command; while ((command = Console.ReadLine()) != "End") { var animalData = command.Split(); var foodData = Console.ReadLine().Split(); IAnimal animal = animalFactory.CreateAnimal(animalData); IFood food = foodFactory.CreateFood(foodData[0], int.Parse(foodData[1])); animal.ProduceSound(); try { animal.Eat(food); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } animals.Add(animal); } foreach (var animal in animals) { Console.WriteLine(animal); } }
//Processing in humger event of animal. Does feed animal if there is resources (based on random) public void IsInHunger(IAnimal animal) { //emulating feeding animal with some random values var foodProb = _rnd.Next(1, 100); if (foodProb < 96) animal.Eat(foodProb.ToString(CultureInfo.InvariantCulture)); }
public void Run() { string input = Console.ReadLine(); while (input != "End") { try { string[] animalInfo = input.Split(); string[] foodInfo = Console.ReadLine().Split(); string vegType = foodInfo[0]; int vegQuantity = int.Parse(foodInfo[1]); Food.Models.Food food = foodFactory.GenerateFood(vegType, vegQuantity); string type = animalInfo[0]; string name = animalInfo[1]; double weight = double.Parse(animalInfo[2]); if (type == "Cat" || type == "Tiger") { string livingRegion = animalInfo[3]; string breed = animalInfo[4]; animal = felineFactory.GenerateFeline(type, name, weight, livingRegion, breed); } else if (type == "Dog" || type == "Mouse") { string livingRegion = animalInfo[3]; animal = mammalFactory.GenerateAnimal(type, name, weight, livingRegion); } else if (type == "Owl" || type == "Hen") { double wingSize = double.Parse(animalInfo[3]); animal = birdsFactory.CreateBird(type, name, weight, wingSize); } animals.Add(animal); animal.ProduceSound(); animal.Eat(food); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } input = Console.ReadLine(); } foreach (var animal in animals) { Console.WriteLine(animal); } }
public void Run() { string input; var countLines = 0; while ((input = Console.ReadLine()) != "End") { try { if (countLines % 2 == 0) { try { var animalInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); animal = animalFactory.CreateAnimal(animalInfo); countLines++; continue; } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { try { var foodInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); food = foodFactory.CreateFood(foodInfo); countLines++; } catch (Exception ex) { Console.WriteLine(ex.Message); } } try { Console.WriteLine(animal.ProduceSound()); animal.Eat(food); } catch (Exception ex) { Console.WriteLine(ex.Message); } animals.Add(animal); } catch (Exception) { throw; } } animals.ForEach(a => Console.WriteLine(a)); }
//Processing in humger event of animal. Does feed animal if there is resources (based on random) public void IsInHunger(IAnimal animal) { //emulating feeding animal with some random values var foodProb = _rnd.Next(1, 100); if (foodProb < 96) { animal.Eat(foodProb.ToString(CultureInfo.InvariantCulture)); } }
public static void TryEatFood(IAnimal animal, IFood food) { try { animal.Eat((IFood)food); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void Run() { string command = ""; while ((command = Console.ReadLine()) != "End") { string[] animalInfo = command.Split(); string[] foodInfo = Console.ReadLine().Split(); string animalType = animalInfo[0].ToLower(); string name = animalInfo[1]; double weight = double.Parse(animalInfo[2]); if (animalType == "cat" || animalType == "tiger") { string livingRegion = animalInfo[3]; string breed = animalInfo[4]; animal = (IAnimal)felineFactory.CreateFeline(animalType, name, weight, livingRegion, breed); } else if (animalType == "owl" || animalType == "hen") { double wingSize = double.Parse(animalInfo[3]); animal = (IAnimal)birdFactory.CreateBird(animalType, name, weight, wingSize); } else if (animalType == "mouse" || animalType == "dog") { string livingRegion = animalInfo[3]; animal = (IAnimal)mammalFactory.CreateMammal(animalType, name, weight, livingRegion); } animals.Add(animal); animal.ProduceSound(); try { string foodType = foodInfo[0]; double quantity = double.Parse(foodInfo[1]); IFood food = foodFactory.CreateFood(foodType, quantity); animal.Eat(food); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } foreach (var animal in this.animals) { Console.WriteLine(animal); } }
public void Run() { int line = 0; string input = Console.ReadLine(); while (input != "End") { if (line % 2 == 0) { IAnimal animal = animalFactory.CreateAnimal(input.Split()); if (animal == null) { continue; } animals.Add(animal); } else { IFood food = foodFactory.CreateFood(input.Split()); if (food == null) { continue; } foods.Add(food); } line++; input = Console.ReadLine(); } for (int i = 0; i < foods.Count; i++) { IAnimal animal = animals[i]; IFood food = foods[i]; Console.WriteLine(animal.ProduceSound()); try { animal.Eat(food); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } foreach (var animal in animals) { Console.WriteLine(animal); } }
static void Main(string[] args) { Console.WriteLine("Animals"); Factory factory = Factory.GetFactory(); IAnimal animal1 = factory.GetAnimal("wolf"); animal1.Eat(); IAnimal animal2 = factory.GetAnimal("lion"); animal2.Eat(); IAnimal nullAnimal = factory.GetAnimal("donut"); nullAnimal.Eat(); //will do nothing }
public void Run() { string input = string.Empty; while ((input = Console.ReadLine()) != "End") { string[] animalInfo = input.Split(); string animalType = animalInfo[0]; string animalName = animalInfo[1]; double animalWeight = double.Parse(animalInfo[2]); if (animalType == "Hen" || animalType == "Owl") { double wingSize = double.Parse(animalInfo[3]); animal = birdFactory.CreateBird(animalType, animalName, animalWeight, wingSize); } else if (animalType == "Dog" || animalType == "Mouse") { string livingregion = animalInfo[3]; animal = mammalFactory.CreateMammal(animalType, animalName, animalWeight, livingregion); } else if (animalType == "Cat" || animalType == "Tiger") { string livingregion = animalInfo[3]; string breed = animalInfo[4]; animal = felineFactory.CreateFeline(animalType, animalName, animalWeight, livingregion, breed); } string[] foodInfo = Console.ReadLine().Split(); string foodType = foodInfo[0]; int foodQuantity = int.Parse(foodInfo[1]); Food food = foodFactory.CreateFood(foodType, foodQuantity); animal.ProduceSound(); animal.Eat(food); animals.Add(animal); } foreach (var animal in animals) { Console.WriteLine(animal); } }
public void Run() { string[] info = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); bool isOddLine = false; FoodFactory foodFactory = new FoodFactory(); ICollection <IFood> foods = new List <IFood>(); AnimalFactory animalFactory = new AnimalFactory(); ICollection <IAnimal> animals = new List <IAnimal>(); while (info[0]?.ToLower() != "end") { if (isOddLine) { isOddLine = false; IFood food = foodFactory.CreateFood(info); IAnimal animal = animals.Last(); try { animal.Eat(food); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } } else { isOddLine = true; IAnimal animal = animalFactory.CreateAnimal(info); animal.ProduceSound(); animals.Add(animal); } info = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); } foreach (var animal in animals) { Console.WriteLine(animal); } }
public void Run() { string input = string.Empty; while ((input = Console.ReadLine()) != "End") { string[] animalInput = input .Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); IAnimal newAnimal = AnimalCreator.CreateAnimal(animalInput); string[] foodInput = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); newAnimal.Eat(foodInput[0], int.Parse(foodInput[1])); listOfAnimals.Add(newAnimal); } Printing(); }
public void Proceed() { IAnimal animal = null; IFood food = null; var input = ""; while ((input = this.reader.ReadLine()) != "End") { var animalData = input .Split() .ToArray(); var foodData = this.reader .ReadLine() .Split() .ToArray(); animal = this.animalFactory.CreateAnimal(animalData); this.animalsList.Add(animal); food = this.foodFactory.CreateFood(foodData); this.writer.WriteLine(animal.ProduceSound()); try { animal.Eat(food); } catch (ArgumentException e) { this.writer.WriteLine(e.Message); } } Print(); }
public void Run() { List <IAnimal> animals = new List <IAnimal>(); string input = string.Empty; while ((input = Console.ReadLine()) != "End") { string[] animalElements = input .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); IAnimal animal = AnimalFactory.Create(animalElements); animals.Add(animal); Console.WriteLine(animal.ProduceSound()); string[] foodElements = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); IFood food = FoodFactory.Create(foodElements); try { animal.Eat(food); } catch (Exception ex) { Console.WriteLine(ex.Message); } } foreach (IAnimal animal in 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); IFood food = this.foodFactory.ProduceFood(foodArgs[0], int.Parse(foodArgs[1])); this.animals.Add(animal); Console.WriteLine(animal.ProduceSound()); try { animal.Eat(food); } catch (Exception ex) { Console.WriteLine(ex.Message); } } foreach (IAnimal animal1 in this.animals) { Console.WriteLine(animal1); } }
public void Execute() { IAnimal animalToFeed = _animals.GetAnimals().First(a => a.GetName() == _name); animalToFeed.Eat(); }
public virtual string Eat() { return(_animal.Eat()); }
public void _3_TestElephantEat() { elephant.Eat(); Assert.AreEqual("Elephant ElephantTest is 5 years old. It is currently 0 hungry and 15 energetic.", elephant.GetState()); }
public void _3_TestPenguinEat() { penguin.Eat(); Assert.AreEqual("Penguin PenguinTest is 5 years old. It is currently 0 hungry and 15 energetic.", penguin.GetState()); }
private static void FactoryExample() { IAnimalFactory factory = AnimalFactory.CreateFactory(); IAnimal carnivore = factory.CreateAnimal(AnimalType.Carnivore); IAnimal herbivore = factory.CreateAnimal(AnimalType.Herbivore); Console.WriteLine("I am a {0}, i sleep for {1} hours and like to eat {2}", carnivore.GetType().Name, carnivore.Sleep(), carnivore.Eat()); Console.WriteLine("I am a {0}, i sleep for {1} hours and like to eat {2}", herbivore.GetType().Name, herbivore.Sleep(), herbivore.Eat()); }
public static void Main() { var inputLines = new List <string>(); string inputLine; while ((inputLine = Console.ReadLine()) != "End") { inputLines.Add(inputLine); } var animals = new List <IAnimal>(); IAnimal animal = null; for (int i = 0; i < inputLines.Count; i++) { if (i % 2 == 0) { var animalInfo = inputLines[i].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var type = animalInfo[0]; var name = animalInfo[1]; var weight = double.Parse(animalInfo[2]); switch (type) { case "Cat": case "Tiger": var felineLivingRegion = animalInfo[3]; var breed = animalInfo[4]; if (type == "Cat") { IAnimal cat = new Cat(name, weight, felineLivingRegion, breed); animal = cat; } else if (type == "Tiger") { IAnimal tiger = new Tiger(name, weight, felineLivingRegion, breed); animal = tiger; } break; case "Owl": case "Hen": var wingSize = double.Parse(animalInfo[3]); if (type == "Owl") { IAnimal owl = new Owl(name, weight, wingSize); animal = owl; } else if (type == "Hen") { IAnimal hen = new Hen(name, weight, wingSize); animal = hen; } break; case "Dog": case "Mouse": var mammalLivingRegion = animalInfo[3]; if (type == "Dog") { IAnimal dog = new Dog(name, weight, mammalLivingRegion); animal = dog; } else if (type == "Mouse") { IAnimal mouse = new Mouse(name, weight, mammalLivingRegion); animal = mouse; } break; } animals.Add(animal); } else { var foodInfo = inputLines[i].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var foodType = foodInfo[0]; var quantity = int.Parse(foodInfo[1]); Console.WriteLine(animal.Eat(foodType, quantity)); } } foreach (var currentAnimal in animals) { Console.WriteLine(currentAnimal); } }
public void DaliyPlay() { _animal.Sleep(); _animal.Eat(); _animal.Walk(); }
private static void FeedAnimal(IAnimal animal) { animal.Eat(); }
public void Eat() { m_animal.Eat(); }