public void Eat(Food food) { if (!AllowedFoods.Contains(food.GetType().Name)) { throw new InvalidOperationException($"{GetType().Name} does not eat {food.GetType().Name}!"); } Weight += food.Quantity * WeightModifier; FoodEaten += food.Quantity; }
public void Eat(Food food) { if (!AllowedFoods.Contains(food.GetType())) { throw new ArgumentException($"{this.GetType().Name} does not eat {food.GetType().Name}!"); } Weight += food.Quantity * IncreasedConst; FoodEaten += food.Quantity; }
public void EatingFood(Food food) { if (!AllowedFoods.Contains(food.GetType().Name)) { Console.WriteLine($"{this.GetType().Name} does not eat {food.GetType().Name}!"); return; } FoodEaten += food.Quantity; Weight += food.Quantity * WeightModifire; }
public void Eat(Food food) { string foodTypeName = food.GetType().Name; if (!AllowedFoods.Contains(food.GetType().Name)) { throw new InvalidOperationException($"{this.GetType().Name} does not eat {foodTypeName}!"); } this.FoodEaten += food.Quantity; this.Weight += this.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; }