public void Eat(Food food) { if (!AllowedFoods.Contains(food.GetType().Name)) { throw new InvalidOperationException($"{GetType().Name} does not eat {food.GetType().Name}!"); } FoodEaten += food.Quantity; Weight += food.Quantity * WeightModifier; }
public void Eat(Food food) { if (!this.eatableFood.Contains(food.GetType().Name)) { throw new ArgumentException($"{this.GetType().Name} does not eat {food.GetType().Name}!"); } this.Weight += food.Quantity * weightGain; this.FoodEaten += food.Quantity; }
public void Eat(Food food) { if (this.Foods.Contains(food.GetType().Name)) { this.FoodEaten += food.Quantity; this.Weight += this.WeightRate * food.Quantity; } else { throw new ArgumentException($"{this.GetType().Name} does not eat {food.GetType().Name}!"); } }
public override void Feed(Food food) { if (food.GetType().Name == "Fruit" || food.GetType().Name == "Vegetable") { this.Weight += 0.1 * food.Quantity; this.FoodEaten += food.Quantity; } else { Console.WriteLine($"{this.GetType().Name} does not eat {food.GetType().Name}!"); } }
public override void Eat(Food food) { if (food.GetType().Name == "Meat") { this.Weight += 0.25 * food.Quantity; this.FoodEaten += food.Quantity; } else { Console.WriteLine($"{this.GetType().Name} does not eat {food.GetType().Name}!"); } }
public override void Eat(Food food) { var foodType = food.GetType(); this.Weight += food.Quantity * 0.35; FoodEaten += food.Quantity; }
protected override void ValidateFood(Food food) { if (food.GetType().Name != nameof(Meat)) { this.Throw(food); } }
public override void Eat(Food food) { if (food.GetType().Name == "Meal") { throw new InvalidOperationException($"{this.GetType().Name} are not eating that type of food!"); } base.FoodEaten = food.Quantity; }
public override void EatFood(Food food) { if (food.GetType().Name != "Meat") { throw new ArgumentException($"{this.GetType().Name}s are not eating that type of food!"); } this.FoodEaten = food.Quantity; }
protected override void ValidateFood(Food food) { string type = food.GetType().Name; if (type != nameof(Vegetable) && type != nameof(Fruit)) { Throw(food); } }
protected override void ValidateFood(Food food) { string type = food.GetType().Name; if (type != nameof(Meat)) { Throw(food); } }
public override void Eat(Food food) { if (!(food is Meat)) { throw new ArgumentException($"{this.GetType().Name} does not eat {food.GetType().Name}!"); } this.FoodEaten += food.Quantity; this.Weight += increasedWeightByEating * food.Quantity; }
public override void Eat(Food food) { if (!(food is Meat)) { throw new ArgumentException($"{this.GetType().Name} does not eat {food.GetType().Name}!"); } this.Weight += food.Quantity * WEIGHT_INCREASE_PER_FOOD; this.FoodEaten += food.Quantity; }
public void TryEatFood(Food food) { Type typeOfFood = food.GetType(); if (!this.PreferredFoods.Contains(typeOfFood)) { throw new InvalidOperationException($"{this.GetType().Name} does not eat {typeOfFood.Name}!"); } this.FoodEaten += food.Quantity; this.Weight += food.Quantity * this.WeightIncreaseMultiplier; }
public void Eat(Food food) { if (!this.AlowedFood.Contains(food.GetType().Name)) { throw new InvalidOperationException($"{this.GetType().Name} does not eat {food.GetType().Name}!"); } this.FoodEaten += food.Quantity; this.Weight += this.WeightModifire * this.FoodEaten; }
public void EatFood(Food food) { Type typeOfFood = food.GetType(); if (!this.PreferredFood.Contains(typeOfFood)) { throw new ArgumentException($"{this.GetType().Name} does not eat {typeOfFood.Name}!"); } this.FoodEaten += food.Quantity; this.Weight += food.Quantity * this.IncreaseWeight; }
public void Feed(Food food) { if (foodAcceptable.Contains(food.GetType().Name)) { FoodEaten += food.Quantity; Weight += food.Quantity * weightIncrement; } else { throw new InvalidOperationException($"{this.GetType().Name} does not eat {food.GetType().Name}!"); } }
public override void Feed(Food food) { if (food is Meat) { this.Weight += food.Quantity * 0.25; this.FoodEaten += food.Quantity; } else { Console.WriteLine($"{this.GetType().Name} does not eat {food.GetType().Name}!"); } }
public override void Eat(Food food) { var foodType = food.GetType(); if (foodType.Equals(typeof(Vegetable)) || foodType.Equals(typeof(Fruit))) { this.Weight += food.Quantity * 0.10; FoodEaten += food.Quantity; } else { Console.WriteLine($"Mouse does not eat {foodType.Name}!"); } }
public override void Eat(Food food) { var foodType = food.GetType(); if (foodType.Equals(typeof(Meat))) { this.Weight += food.Quantity * 0.25; FoodEaten += food.Quantity; } else { Console.WriteLine($"Owl does not eat {foodType.Name}!"); } }
public void Eat(Food food) { string foodTypeName = food.GetType().Name; //1.Validate food if (!AllowedFoods.Contains(foodTypeName)) { throw new InvalidOperationException($"{this.GetType().Name} does not eat {foodTypeName}!"); } //2.Food Eaten FoodEaten += food.Quantity; //3.Weigth Weight += WeightModifier * food.Quantity; }
public void Eat(Food food) { string fooodType = food.GetType().Name; //1. Validate the food can eat if (!AllowedFoods.Contains(fooodType)) { //• "{AnimalType} does not eat {FoodType}!" throw new InvalidOperationException($"{this.GetType().Name} does not eat {fooodType}!"); } else { //2. FoodEaten ++ this.FoodEaten += food.Qunatity; } //3. Weight ++ this.Weight += WeightModifier * food.Qunatity; }
private static void TryToEat(Animal animal, Food food) { if (animal.GetType().Name.ToLower() == "hen") { animal.Weight += 0.35 * food.Quantity; animal.FoodEaten = food.Quantity; } else if (animal.GetType().Name.ToLower() == "mouse" && (food.GetType().Name.ToLower() == "vegetable" || food.GetType().Name.ToLower() == "fruit")) { animal.Weight += 0.10 * food.Quantity; animal.FoodEaten = food.Quantity; } else if (animal.GetType().Name.ToLower() == "cat" && (food.GetType().Name.ToLower() == "vegetable" || food.GetType().Name.ToLower() == "meat")) { animal.Weight += 0.30 * food.Quantity; animal.FoodEaten = food.Quantity; } else if (animal.GetType().Name.ToLower() == "owl" && food.GetType().Name.ToLower() == "meat") { animal.Weight += 0.25 * food.Quantity; animal.FoodEaten = food.Quantity; } else if (animal.GetType().Name.ToLower() == "tiger" && food.GetType().Name.ToLower() == "meat") { animal.Weight += 1 * food.Quantity; animal.FoodEaten = food.Quantity; } else if (animal.GetType().Name.ToLower() == "dog" && food.GetType().Name.ToLower() == "meat") { animal.Weight += 0.40 * food.Quantity; animal.FoodEaten = food.Quantity; } else { Console.WriteLine($"{animal.GetType().Name} does not eat {food.GetType().Name}!"); } }
public static void Main(string[] args) { var animals = new List <Animal>(); var animalsCreator = new AnimalCreatorFactory(); var foodCreator = new FoodCreatorFactory(); string input = Console.ReadLine(); while (input != "End") { var data = input?.Split(" "); Animal animal = animalsCreator.Create(data[0], data); input = Console.ReadLine(); data = input?.Split(" "); Food food = foodCreator.Create(int.Parse(data[1]), data[0]); Console.WriteLine(animal.AskForFood()); var canEat = animal.CanEat(food); if (canEat) { animal.IncreaseWeight(food.Quantity); } else { Console.WriteLine($"{animal.GetType().Name} does not eat {food.GetType().Name}!"); } animals.Add(animal); input = Console.ReadLine(); } foreach (var animal in animals) { Console.WriteLine(animal.ToString()); } }
static void Main() { List <Animal> animals = new List <Animal>(); string command = Console.ReadLine(); while (command != "End") { Animal newAnimal = AnimalCreator.CreateAnimal(command); try { Food newFood = FoodCreator.CreateFood(Console.ReadLine()); newAnimal.AskForFood(); if (newAnimal.AcceptedFoods.Contains(newFood.GetType().Name)) { newAnimal.FoodEaten += newFood.Quantity; newAnimal.Weight += newAnimal.WeightIncrease * newFood.Quantity; } else { throw new ArgumentException($"{newAnimal.GetType().Name} does not eat {newFood.GetType().Name}!"); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } animals.Add(newAnimal); command = Console.ReadLine(); } foreach (Animal animal in animals) { Console.WriteLine(animal.ToString()); } }
public override void Eat(Food food) { if (food is Vegetable || food is Fruit) { IncreaseWeightAndFoodEaten(WeightIncrease(food.Quantity), food.Quantity); } else { throw new ArgumentException(String.Format(GlobalConstants.AnimalDoesNotEat_Exc_Msg, GetType().Name, food.GetType().Name)); } }
public virtual void Eat(Food food) { if (food is Meat) { FoodEaten += food.Quantity; Weight += WeightIncrease(food.Quantity); } else { throw new ArgumentException(String.Format(GlobalConstants.AnimalDoesNotEat_Exc_Msg, GetType().Name, food.GetType().Name)); } }
protected void Throw(Food food) { throw new ArgumentException($"{this.GetType().Name} does not eat {food.GetType().Name}!"); }