Exemple #1
0
        /*
         * Calculate the feeding cost as follows:
         * feedingCost = foodPricePerKg * amountOfFoodNeeded
         * */
        public double CalculateAnimalFeedingCost(ZooContentInfo zooContentInfo)
        {
            RateInfo rateInfo = GetRateInfoForAnimal(zooContentInfo.animalType);

            // foodPricePerKg
            var meatPricePerKg  = Double.Parse(GetFoodPricePerKg(Food.Meat.ToString()), CultureInfo.InvariantCulture);
            var fruitPricePerKg = Double.Parse(GetFoodPricePerKg(Food.Fruit.ToString()), CultureInfo.InvariantCulture);

            // carnivore
            if (rateInfo.foodType.Equals(Carnivore.foodType.ToLower()))
            {
                Carnivore carnivore          = new Carnivore(zooContentInfo.animalType, zooContentInfo.name, zooContentInfo.weight);
                var       amountOfFoodNeeded = carnivore.CalculateAmountOfFoodNeeded(rateInfo);
                var       feedingCost        = meatPricePerKg * amountOfFoodNeeded;
                totalFeedingCost = totalFeedingCost + feedingCost;
                Console.Write("\t\t\t\t" + Carnivore.foodType + "\t\t" + meatPricePerKg + "\t\t" + amountOfFoodNeeded + "Kg" + "\t\t" + meatPricePerKg + " * " + amountOfFoodNeeded + " = " + feedingCost + "\t\t" + "\n");
                return(feedingCost);
            }

            // herbivore
            if (rateInfo.foodType.Equals(Herbivore.foodType.ToLower()))
            {
                Herbivore herbivore          = new Herbivore(zooContentInfo.animalType, zooContentInfo.name, zooContentInfo.weight);
                var       amountOfFoodNeeded = herbivore.CalculateAmountOfFoodNeeded(rateInfo);
                var       feedingCost        = fruitPricePerKg * amountOfFoodNeeded;
                totalFeedingCost = totalFeedingCost + feedingCost;

                Console.Write("\t\t\t\t" + Herbivore.foodType + "\t\t" + fruitPricePerKg + "\t\t" + amountOfFoodNeeded + "Kg" + "\t\t" + fruitPricePerKg + " * " + amountOfFoodNeeded + " = " + feedingCost + "  " + "\t\t" + "\n");

                return(feedingCost);
            }

            // omnivore
            if (rateInfo.foodType.Equals(Omnivore.foodType.ToLower()))
            {
                Omnivore omnivore = new Omnivore(zooContentInfo.animalType, zooContentInfo.name, zooContentInfo.weight);

                // meat
                rateInfo.foodType = Food.Meat.ToString();
                var amountOfMeatNeeded = omnivore.CalculateAmountOfFoodNeeded(rateInfo);
                var feedingCostMeat    = meatPricePerKg * amountOfMeatNeeded;
                totalFeedingCost = totalFeedingCost + feedingCostMeat;

                Console.Write("\t\t\t\t" + Food.Meat.ToString() + "\t\t" + meatPricePerKg + "\t\t" + amountOfMeatNeeded + "Kg" + "\t\t" + meatPricePerKg + " * " + amountOfMeatNeeded + " = " + feedingCostMeat + "\t\t" + "\n");

                // fruit
                rateInfo.foodType = Food.Fruit.ToString();
                var amountOfFruitNeeded = omnivore.CalculateAmountOfFoodNeeded(rateInfo);
                var feedingCostFruit    = fruitPricePerKg * amountOfFruitNeeded;
                //var feedingCost = feedingCostFruit + feedingCostMeat;
                totalFeedingCost = totalFeedingCost + feedingCostFruit;

                Console.Write("\t\t\t\t" + Food.Fruit.ToString() + "\t\t" + fruitPricePerKg + "\t\t" + amountOfFruitNeeded + "Kg" + "\t\t" + fruitPricePerKg + " * " + amountOfFruitNeeded + " = " + feedingCostFruit + "\t\t" + "\n");
                return(feedingCostFruit + feedingCostMeat);
            }

            return(0.0);
        }
Exemple #2
0
        // amount of food needed depends on the weight.
        // the rate determines how much food is needed. For omnivores, the rate must be split into meat and fruit
        public override double CalculateAmountOfFoodNeeded(RateInfo rateInfo)
        {
            double amountOfFoodNeeded = 0.0;

            // meat
            if (rateInfo.foodType.Equals(Food.Meat.ToString()))
            {
                amountOfFoodNeeded = weight * rateInfo.percentage * rateInfo.rate;
            }

            // fruit
            if (rateInfo.foodType.Equals(Food.Fruit.ToString()))
            {
                amountOfFoodNeeded = weight * (1 - rateInfo.percentage) * rateInfo.rate;
            }

            return(amountOfFoodNeeded);
        }
Exemple #3
0
        /**
         * Extract information regarding the animal species present in the zoo from animal.csv
         **/
        public RateInfo GetRateInfoForAnimal(string animal)
        {
            var result = File.ReadLines("animals.csv").Select(line => line.Split(';'));

            Dictionary <string, RateInfo> dictionary = new Dictionary <string, RateInfo>();

            foreach (string[] aText in result)
            {
                var rate = Double.Parse(aText[1], CultureInfo.InvariantCulture);

                double percentage = 0.0;
                if (aText[3] != "")
                {
                    percentage = (double.Parse(aText[3].TrimEnd(new char[] { '%', ' ' }))) / 100;
                }


                RateInfo rateInfo = new RateInfo(rate, aText[2], percentage);
                dictionary.Add(aText[0], rateInfo);
            }

            return(dictionary[animal]);
        }
Exemple #4
0
 // Each animal eats an amount of food that depends on its weight
 public abstract double CalculateAmountOfFoodNeeded(RateInfo rateInfo);
Exemple #5
0
 public override double CalculateAmountOfFoodNeeded(RateInfo rateInfo)
 {
     return(weight * rateInfo.rate);
 }