void Update() { Hen under = findHenUnder(); bool henFound = false; if (under != null) { henFound = true; if (brushProgress == 0 || lastHen.GetInstanceID() != under.GetInstanceID()) { StopHenFlap(lastHen); lastHen = under; brushProgress = maxBrushTimer; MakeHenFlap(lastHen); SoundManager.Instance().PlayAnySFX(SoundManager.SFXv2.Brush); } } if (!henFound && checkHenStillBeingPetTimer < 0) { StopHenFlap(lastHen); brushProgress = 0; } if (checkHenStillBeingPetTimer < 0) { checkHenStillBeingPetTimer = 0.5f; } checkHenStillBeingPetTimer -= Time.deltaTime; if (brushProgress > 0) { brushProgress -= Time.deltaTime; if (brushProgress <= 0) { StartCoroutine(lastHen.love.increase(1 + .5f * InventoryPersist.getPettingLevel())); brushProgress = 0; } } else { brushProgress = 0; } }
private static IAnimal ProduseAnimal(string[] animalArgs, string animalType, string name, double weight) { IAnimal animal = null; if (animalType == "Owl") { var wingSize = double.Parse(animalArgs[3]); animal = new Owl(name, weight, wingSize); } else if (animalType == "Hen") { var wingSize = double.Parse(animalArgs[3]); animal = new Hen(name, weight, wingSize); } else { var leivingRegion = animalArgs[3]; if (animalType == "Dog") { animal = new Dog(name, weight, leivingRegion); } else if (animalType == "Mouse") { animal = new Mouse(name, weight, leivingRegion); } else { var breed = animalArgs[4]; if (animalType == "Cat") { animal = new Cat(name, weight, leivingRegion, breed); } else if (animalType == "Tiger") { animal = new Tiger(name, weight, leivingRegion, breed); } } } return(animal); }
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; } }
public void MakeNoiseTest() { var farm = new EmydexFarmSystem(); Cow cow = new Cow(); farm.Enter(cow); Hen hen = new Hen(); farm.Enter(hen); Horse horse = new Horse(); farm.Enter(horse); Sheep sheep = new Sheep(); farm.Enter(sheep); Assert.AreEqual(farm.AnimalsCurrentlyInFarm(), 4); farm.MakeNoise(); }
private static Animal GetAnimal(string[] tokens) { string type = tokens[0]; string name = tokens[1]; double weight = double.Parse(tokens[2]); Animal animal = null; switch (type) { case "Cat": animal = new Cat(name, weight, tokens[3], tokens[4]); break; case "Dog": animal = new Dog(name, weight, tokens[3]); break; case "Mouse": animal = new Mouse(name, weight, tokens[3]); break; case "Tiger": animal = new Tiger(name, weight, tokens[3], tokens[4]); break; case "Hen": animal = new Hen(name, weight, double.Parse(tokens[3])); break; case "Owl": animal = new Owl(name, weight, double.Parse(tokens[3])); break; default: Console.WriteLine("Invalid type"); break; } return(animal); }
private static Animal CreateAnimal(List <Animal> animals, string[] animalTokens, string type, string name, double weight, Animal newAnimal) { switch (type) { case "Hen": newAnimal = new Hen(name, weight, double.Parse(animalTokens[3])); animals.Add(newAnimal); break; case "Owl": newAnimal = new Owl(name, weight, double.Parse(animalTokens[3])); animals.Add(newAnimal); break; case "Dog": newAnimal = new Dog(name, weight, animalTokens[3]); animals.Add(newAnimal); break; case "Mouse": newAnimal = new Mouse(name, weight, animalTokens[3]); animals.Add(newAnimal); break; case "Cat": newAnimal = new Cat(name, weight, animalTokens[3], animalTokens[4]); animals.Add(newAnimal); break; case "Tiger": newAnimal = new Tiger(name, weight, animalTokens[3], animalTokens[4]); animals.Add(newAnimal); break; default: break; } return(newAnimal); }
void Update() { Hen under = findHenUnder(); bool henFound = false; if (under != null) { henFound = true; if (brushProgress == 0 || lastHen.GetInstanceID() != under.GetInstanceID()) { StopHenFlap(lastHen); lastHen = under; brushProgress = maxBrushTimer; MakeHenFlap(lastHen); } } if (!henFound && checkHenStillBeingPetTimer < 0) { StopHenFlap(lastHen); brushProgress = 0; } if (checkHenStillBeingPetTimer < 0) { checkHenStillBeingPetTimer = 0.5f; } checkHenStillBeingPetTimer -= Time.deltaTime; if (brushProgress > 0) { brushProgress -= Time.deltaTime; if (brushProgress <= 0) { StartCoroutine(lastHen.love.increase(1)); brushProgress = 0; } } else { brushProgress = 0; } }
private Animal CreateAnimal(string type, string[] info) { Animal animal = null; if (type == "Hen") { double wingSize = double.Parse(info[3]); animal = new Hen(info[1], double.Parse(info[2]), wingSize); } else if (type == "Owl") { double wingSize = double.Parse(info[3]); animal = new Owl(info[1], double.Parse(info[2]), wingSize); } else if (type == "Mouse") { string region = info[3]; animal = new Mouse(info[1], double.Parse(info[2]), region); } else if (type == "Dog") { string region = info[3]; animal = new Dog(info[1], double.Parse(info[2]), region); } else if (type == "Cat") { string region = info[3]; string breed = info[4]; animal = new Cat(info[1], double.Parse(info[2]), region, breed); } else if (type == "Tiger") { string region = info[3]; string breed = info[4]; animal = new Tiger(info[1], double.Parse(info[2]), region, breed); } return(animal); }
public static Animal Create(string[] args) { string type = args[0]; string name = args[1]; double weight = double.Parse(args[2]); Animal animal = null; if (type == "Owl") { animal = new Owl(name, weight, double.Parse(args[3])); } else if (type == "Hen") { animal = new Hen(name, weight, double.Parse(args[3])); } else if (type == "Cat") { animal = new Cat(name, weight, args[3], args[4]); } else if (type == "Tiger") { animal = new Tiger(name, weight, args[3], args[4]); } else if (type == "Dog") { animal = new Dog(name, weight, args[3]); } else if (type == "Mouse") { animal = new Mouse(name, weight, args[3]); } else if (animal == null) { throw new ArgumentException(String.Format(ExceptionHandling.INVALID_FOOD_TYPE, type)); } return(animal); }
private IAnimal GetAnimal(string command) { string[] animalArgs = command.Split(" ").ToArray(); string type = animalArgs[0]; string name = animalArgs[1]; double weight = double.Parse(animalArgs[2]); IAnimal animal; if (type == "Owl") { double wingSize = double.Parse(animalArgs[3]); animal = new Owl(name, weight, wingSize); } else if (type == "Hen") { double wingSize = double.Parse(animalArgs[4]); animal = new Hen(name, weight, wingSize); } else { string livingregion = animalArgs[4]; if (type == "Dog") { animal = new Dog(name, weight, livingregion); } else if (type == "Mouse") { animal = new Mouse(name, weight, livingregion); } else { string breed = animalArgs[5]; } } }
public static Animal CreateAnimal(string[] animalData) { Animal animal = null; string animalType = animalData[0]; string animalName = animalData[1]; double animalWeight = double.Parse(animalData[2]); if (animalType == "Owl" || animalType == "Hen") { double wingSize = double.Parse(animalData[3]); if (animalType == "Owl") { return(animal = new Owl(animalName, animalWeight, wingSize)); } return(animal = new Hen(animalName, animalWeight, wingSize)); } else if (animalType == "Dog" || animalType == "Mouse") { string livingRegion = animalData[3]; if (animalType == "Dog") { return(animal = new Dog(animalName, animalWeight, livingRegion)); } return(animal = new Mouse(animalName, animalWeight, livingRegion)); } else if (animalType == "Cat" || animalType == "Tiger") { string livingRegion = animalData[3]; string breed = animalData[4]; if (animalType == "Cat") { return(animal = new Cat(animalName, animalWeight, livingRegion, breed)); } return(animal = new Tiger(animalName, animalWeight, livingRegion, breed)); } return(animal); }
public Bird CreateBird( string type, string name, double weight, double wingSize) { type = type.ToLower(); Bird bird = null; switch (type) { case "hen": bird = new Hen(name, weight, wingSize); break; case "owl": bird = new Owl(name, weight, wingSize); break; } return(bird); }
static Animal CreateAnimal(string[] animalData) { string animalType = animalData[0]; string animalName = animalData[1]; double animalWeight = double.Parse(animalData[2]); Animal newAnimal = null; switch (animalType) { case "Hen": newAnimal = new Hen(animalName, animalWeight, double.Parse(animalData[3])); break; case "Owl": newAnimal = new Owl(animalName, animalWeight, double.Parse(animalData[3])); break; case "Cat": newAnimal = new Cat(animalName, animalWeight, animalData[3], animalData[4]); break; case "Tiger": newAnimal = new Tiger(animalName, animalWeight, animalData[3], animalData[4]); break; case "Dog": newAnimal = new Dog(animalName, animalWeight, animalData[3]); break; case "Mouse": newAnimal = new Mouse(animalName, animalWeight, animalData[3]); break; } return(newAnimal); }
public static Animal CreateAnimal(string[] parms) { Animal animal = null; string type = parms[0]; string name = parms[1]; double weight = double.Parse(parms[2]); if (type == "Hen") { double wingSize = double.Parse(parms[3]); animal = new Hen(name, weight, wingSize); } else if (type == "Owl") { double wingSize = double.Parse(parms[3]); animal = new Owl(name, weight, wingSize); } else if (type == "Mouse") { animal = new Mouse(name, weight, parms[3]); } else if (type == "Cat") { animal = new Cat(name, weight, parms[3], parms[4]); } else if (type == "Dog") { animal = new Dog(name, weight, parms[3]); } else if (type == "Tiger") { animal = new Tiger(name, weight, parms[3], parms[4]); } return(animal); }
private static Animal GetAnimalInfo(Animal currAnimal, string[] info) { string typeAnimal = info[0]; string name = info[1]; double weight = double.Parse(info[2]); string livingRegion = info[3]; switch (typeAnimal) { case "Owl": currAnimal = new Owl(name, weight, double.Parse(info[3])); break; case "Hen": currAnimal = new Hen(name, weight, double.Parse(info[3])); break; case "Mouse": currAnimal = new Mouse(name, weight, livingRegion); break; case "Dog": currAnimal = new Dog(name, weight, livingRegion); break; case "Cat": currAnimal = new Cat(name, weight, livingRegion, info[4]); break; case "Tiger": currAnimal = new Tiger(name, weight, livingRegion, info[4]); break; } return(currAnimal); }
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)); }
public static Animal CreateAnimal(string[] animalsParams) { Animal animal = null; string type = animalsParams[0]; string name = animalsParams[1]; double weight = double.Parse(animalsParams[2]); switch (type) { case "Cat": { string livingRegion = animalsParams[3]; string breed = animalsParams[4]; animal = new Cat(name, weight, livingRegion, breed); } break; case "Tiger": { string livingRegion = animalsParams[3]; string breed = animalsParams[4]; animal = new Tiger(name, weight, livingRegion, breed); } break; case "Owl": { double wingSize = double.Parse(animalsParams[3]); animal = new Owl(name, weight, wingSize); } break; case "Hen": { double wingSize = double.Parse(animalsParams[3]); animal = new Hen(name, weight, wingSize); } break; case "Dog": { string livingRegion = animalsParams[3]; animal = new Dog(name, weight, livingRegion); } break; case "Mouse": { string livingRegion = animalsParams[3]; animal = new Mouse(name, weight, livingRegion); } break; default: break; } return(animal); }
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); } }
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; } }
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 Animal Animals(string[] com, Animal type) { if (com[0] == "Hen" || com[0] == "Owl") { var animalName = com[1]; var animalWeight = double.Parse(com[2]); var wingSize = double.Parse(com[3]); if (com[0] == "Hen") { type = new Hen(animalName, animalWeight, wingSize); Console.WriteLine($"{((Hen)type).ProducingSound}"); } else if (com[0] == "Owl") { type = new Owl(animalName, animalWeight, wingSize); Console.WriteLine($"{((Owl)type).ProducingSound}"); } } else if (com[0] == "Cat" || com[0] == "Tiger") { var animalName = com[1]; var animalWeight = double.Parse(com[2]); var livingRegion = com[3]; var breed = com[4]; if (com[0] == "Cat") { type = new Cat(animalName, animalWeight, livingRegion, breed); Console.WriteLine($"{((Cat)type).ProducingSound}"); } else if (com[0] == "Tiger") { type = new Tiger(animalName, animalWeight, livingRegion, breed); Console.WriteLine($"{((Tiger)type).ProducingSound}"); } } else if (com[0] == "Mouse" || com[0] == "Dog") { var animalName = com[1]; var animalWeight = double.Parse(com[2]); var livingRegion = com[3]; if (com[0] == "Mouse") { type = new Mouse(animalName, animalWeight, livingRegion); Console.WriteLine($"{((Mouse)type).ProducingSound}"); } else if (com[0] == "Dog") { type = new Dog(animalName, animalWeight, livingRegion); Console.WriteLine($"{type.ProducingSound}"); } } return(type); }
public Animal Create(string type, string name, double weight, string[] args) { Animal animal; if (args.Length == 1) { bool isBird = double.TryParse(args[0], out double wingSize); if (isBird) { if (type == "Hen") { animal = new Hen(name, weight, wingSize); } else if (type == "Owl") { animal = new Owl(name, weight, wingSize); } else { throw new InvalidOperationException(ExceptionMessages.InvalidType); } } else { string livingRegion = args[0]; if (type == "Mouse") { animal = new Mouse(name, weight, livingRegion); } else if (type == "Dog") { animal = new Dog(name, weight, livingRegion); } else { throw new InvalidOperationException(ExceptionMessages.InvalidType); } } } else if (args.Length == 2) { string livingRegion = args[0]; string breed = args[1]; if (type == "Cat") { animal = new Cat(name, weight, livingRegion, breed); } else if (type == "Tiger") { animal = new Tiger(name, weight, livingRegion, breed); } else { throw new InvalidOperationException(ExceptionMessages.InvalidType); } } else { throw new InvalidOperationException(ExceptionMessages.InvalidType); } return(animal); }
public HttpResponseMessage Post(Hen hen) { return(null); }
static void Main(string[] args) { List <Animal> farm = new List <Animal>(); List <Food> foods = new List <Food>(); string input; while ((input = Console.ReadLine()) != "End") { string[] animalArgs = input.Split(); string[] foodArgs = Console.ReadLine().Split(); string animalType = animalArgs[0]; string animalName = animalArgs[1]; double animalWeight = double.Parse(animalArgs[2]); Animal animal = null; string foodType = foodArgs[0]; int foodQuantity = int.Parse(foodArgs[1]); Food food = null; switch (animalType) { case "Hen": double henWingSize = double.Parse(animalArgs[3]); animal = new Hen(animalName, animalWeight, henWingSize); break; case "Owl": double owlWingSize = double.Parse(animalArgs[3]); animal = new Owl(animalName, animalWeight, owlWingSize); break; case "Mouse": string mouseLivingRegion = animalArgs[3]; animal = new Mouse(animalName, animalWeight, mouseLivingRegion); break; case "Cat": string catLivingRegion = animalArgs[3]; string catBreed = animalArgs[4]; animal = new Cat(animalName, animalWeight, catLivingRegion, catBreed); break; case "Dog": string dogLivingRegion = animalArgs[3]; animal = new Dog(animalName, animalWeight, dogLivingRegion); break; case "Tiger": string tigerLivingRegion = animalArgs[3]; string tigerBreed = animalArgs[4]; animal = new Tiger(animalName, animalWeight, tigerLivingRegion, tigerBreed); break; } switch (foodType) { case "Meat": food = new Meat(foodQuantity); break; case "Fruit": food = new Fruit(foodQuantity); break; case "Seeds": food = new Seeds(foodQuantity); break; case "Vegetable": food = new Vegetable(foodQuantity); break; } farm.Add(animal); foods.Add(food); } int foodIndex = 0; foreach (var animal in farm) { try { animal.AskForFood(); animal.Eat(foods[foodIndex++]); } catch (WrongFoodException ex) { Console.WriteLine(ex.Message); } } farm.ForEach(a => Console.WriteLine(a)); }
static void Main() { var animals = new List <Animal>(); while (true) { var input = Console.ReadLine(); if ("End" == input) { break; } var animalInput = input.Split(); var foodInput = Console.ReadLine().Split(); var type = animalInput[0]; var name = animalInput[1]; var weight = double.Parse(animalInput[2]); Animal animal = null; switch (type) { case "Cat": animal = new Cat(name, weight, animalInput[3], animalInput[4]); break; case "Tiger": animal = new Tiger(name, weight, animalInput[3], animalInput[4]); break; case "Hen": animal = new Hen(name, weight, double.Parse(animalInput[3])); break; case "Owl": animal = new Owl(name, weight, double.Parse(animalInput[3])); break; case "Mouse": animal = new Mouse(name, weight, animalInput[3]); break; case "Dog": animal = new Dog(name, weight, animalInput[3]); break; } var foodType = foodInput[0]; var foodQuantity = int.Parse(foodInput[1]); Food food = null; switch (foodType) { case "Vegetable": food = new Vegetable(foodQuantity); break; case "Fruit": food = new Fruit(foodQuantity); break; case "Meat": food = new Meat(foodQuantity); break; case "Seeds": food = new Seeds(foodQuantity); break; } Console.WriteLine(animal.ProduceSound()); try { animal.Feed(food); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } animals.Add(animal); } foreach (var animal in animals) { Console.WriteLine(animal); } }
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); } } }
public void Put(Guid id, Hen hen) { }
public void Run() { List <Animal> animals = new List <Animal>(); string input = string.Empty; while ((input = Console.ReadLine()) != "End") { string[] animalInfo = input.Split(); string type = animalInfo[0]; string name = animalInfo[1]; double weight = double.Parse(animalInfo[2]); Animal animal = null; if (type == "Owl") { double wingSize = double.Parse(animalInfo[3]); animal = new Owl(name, weight, wingSize); } else if (type == "Hen") { double wingSize = double.Parse(animalInfo[3]); animal = new Hen(name, weight, wingSize); } else if (type == "Mouse") { string livingRegion = animalInfo[3]; animal = new Mouse(name, weight, livingRegion); } else if (type == "Dog") { string livingRegion = animalInfo[3]; animal = new Dog(name, weight, livingRegion); } else if (type == "Cat") { string livingRegion = animalInfo[3]; string breed = animalInfo[4]; animal = new Cat(name, weight, livingRegion, breed); } else if (type == "Tiger") { string livingRegion = animalInfo[3]; string breed = animalInfo[4]; animal = new Tiger(name, weight, livingRegion, breed); } string[] foodInfo = Console.ReadLine().Split(); string foodType = foodInfo[0]; int 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; } Console.WriteLine(animal.ProduceSound()); try { animal.Eat(food); } catch (Exception e) { Console.WriteLine(e.Message); } animals.Add(animal); } foreach (var animal in animals) { Console.WriteLine(animal); } }
public void Run() { List <Animal> animals = new List <Animal>(); string command; Animal animal = null; Food food = null; while ((command = Console.ReadLine()) != "End") { string[] animalInfo = command.Split(); string type = animalInfo[0]; if (type == "Hen") { double weight = double.Parse(animalInfo[2]); int wingSize = int.Parse(animalInfo[3]); animal = new Hen(animalInfo[1], weight, wingSize); } else if (type == "Owl") { double weight = double.Parse(animalInfo[2]); int wingSize = int.Parse(animalInfo[3]); animal = new Hen(animalInfo[1], weight, wingSize); } else if (type == "Mouse") { string name = animalInfo[1]; double weight = double.Parse(animalInfo[2]); string livingRegion = animalInfo[3]; animal = new Mouse(name, weight, livingRegion); } else if (type == "Cat") { string name = animalInfo[1]; double weight = double.Parse(animalInfo[2]); string livingRegion = animalInfo[3]; string breed = animalInfo[4]; animal = new Cat(name, weight, livingRegion, breed); } else if (type == "Tiger") { string name = animalInfo[1]; double weight = double.Parse(animalInfo[2]); string livingRegion = animalInfo[3]; string breed = animalInfo[4]; animal = new Tiger(name, weight, livingRegion, breed); } else if (type == "Dog") { string name = animalInfo[1]; double weight = double.Parse(animalInfo[2]); string livingRegion = animalInfo[3]; animal = new Dog(name, weight, livingRegion); } string foods = Console.ReadLine(); string[] foodInfo = foods.Split(); string foodType = foodInfo[0]; int quantity = int.Parse(foodInfo[1]); if (foodType == "Vegetable") { food = new Vegetable(quantity); } else if (foodType == "Fruit") { food = new Fruit(quantity); } else if (foodType == "Meat") { food = new Meat(quantity); } else if (foodType == "Seeds") { food = new Seeds(quantity); } try { animal.Eat(food); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } } animals.ForEach(Console.WriteLine); }
static void Main(string[] args) { List <string> commands = new List <string>(); List <string> results = new List <string>(); string comm; while ((comm = Console.ReadLine()) != "End") { commands.Add(comm); } for (int i = 1; i < commands.Count; i += 2) { var animalTokens = commands[i - 1] .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); string animalType = animalTokens[0]; string animalName = animalTokens[1]; double animalWeight = double.Parse(animalTokens[2]); if (animalType == "Owl") { int foodEaten = 0; double wingSize = double.Parse(animalTokens[3]); Owl owl = new Owl(animalName, animalWeight, foodEaten, wingSize); WorkWithFood(commands, i, owl, owl.EatingIncrement, owl.EadableFoods, results); } else if (animalType == "Hen") { int foodEaten = 0; double wingSize = double.Parse(animalTokens[2]); Hen hen = new Hen(animalName, animalWeight, foodEaten, wingSize); WorkWithFood(commands, i, hen, hen.EatingIncrement, hen.EadableFoods, results); } else if (animalType == "Mouse") { int foodEaten = 0; string livingRegion = animalTokens[3]; Mouse mouse = new Mouse(animalName, animalWeight, foodEaten, livingRegion); WorkWithFood(commands, i, mouse, mouse.EatingIncrement, mouse.EadableFoods, results); } else if (animalType == "Dog") { int foodEaten = 0; string livingRegion = animalTokens[3]; Dog dog = new Dog(animalName, animalWeight, foodEaten, livingRegion); WorkWithFood(commands, i, dog, dog.EatingIncrement, dog.EadableFoods, results); } else if (animalType == "Cat") { string catLivingRegion = animalTokens[3]; int foodEaten = 0; string catBreed = animalTokens[4]; Cat cat = new Cat(animalName, animalWeight, foodEaten, catLivingRegion, catBreed); WorkWithFood(commands, i, cat, cat.EatingIncrement, cat.EadableFoods, results); } else if (animalType == "Tiger") { string catLivingRegion = animalTokens[3]; int foodEaten = 0; string catBreed = animalTokens[4]; Tiger tiger = new Tiger(animalName, animalWeight, foodEaten, catLivingRegion, catBreed); WorkWithFood(commands, i, tiger, tiger.EatingIncrement, tiger.EadableFoods, results); } } foreach (var item in results) { Console.WriteLine(item); } }