コード例 #1
0
ファイル: Animal.cs プロジェクト: BozhidarN7/SoftUni
 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;
 }
コード例 #2
0
        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;
        }
コード例 #3
0
        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;
        }
コード例 #4
0
ファイル: Animal.cs プロジェクト: yordanov1/SoftUni
        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;
        }
コード例 #5
0
        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;
        }