예제 #1
0
        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;
        }
예제 #2
0
        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;
        }
예제 #3
0
 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}!");
     }
 }
예제 #4
0
 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}!");
     }
 }
예제 #5
0
 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}!");
     }
 }
예제 #6
0
        public override void Eat(Food food)
        {
            var foodType = food.GetType();

            this.Weight += food.Quantity * 0.35;
            FoodEaten   += food.Quantity;
        }
예제 #7
0
 protected override void ValidateFood(Food food)
 {
     if (food.GetType().Name != nameof(Meat))
     {
         this.Throw(food);
     }
 }
예제 #8
0
 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;
 }
예제 #9
0
 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;
 }
예제 #10
0
        protected override void ValidateFood(Food food)
        {
            string type = food.GetType().Name;

            if (type != nameof(Vegetable) && type != nameof(Fruit))
            {
                Throw(food);
            }
        }
예제 #11
0
        protected override void ValidateFood(Food food)
        {
            string type = food.GetType().Name;

            if (type != nameof(Meat))
            {
                Throw(food);
            }
        }
예제 #12
0
 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;
 }
예제 #13
0
        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;
        }
예제 #14
0
        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;
        }
예제 #15
0
        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;
        }
예제 #16
0
        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;
        }
예제 #17
0
파일: Animal.cs 프로젝트: o-todorov/SoftUni
 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}!");
     }
 }
예제 #18
0
 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}!");
     }
 }
예제 #19
0
        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}!");
            }
        }
예제 #20
0
        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}!");
            }
        }
예제 #21
0
        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;
        }
예제 #22
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;
        }
예제 #23
0
 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}!");
     }
 }
예제 #24
0
        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());
            }
        }
예제 #25
0
        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());
            }
        }
예제 #26
0
 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));
     }
 }
예제 #27
0
 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));
     }
 }
예제 #28
0
 protected void Throw(Food food)
 {
     throw new ArgumentException($"{this.GetType().Name} does not eat {food.GetType().Name}!");
 }