Beispiel #1
0
        public double CalculatePrice(double weight, Prices prices)
        {
            double price = 0;

            if (Diet != Diet.Omnivore)
            {
                var foodPrice = Diet == Diet.Herbivore ? prices.Fruits : prices.Meat;
                price = foodPrice * weight * Ratio;
            }
            else
            {
                var meatRatio  = Ratio * MeatPercent;
                var fruitRatio = Ratio - meatRatio;
                price = prices.Fruits * weight * fruitRatio + prices.Meat * weight * meatRatio;
            }

            return(Math.Round(price, 3));
        }
Beispiel #2
0
 private static double CalculateCost(IEnumerable <Animal> animals, AnimalType type, Prices prices)
 {
     return(animals.Where(animal => animal.IsType(type))
            .Aggregate(0.0, ((cost, animal) => cost + animal.CalculatePrice(prices))));
 }
Beispiel #3
0
 public double CalculatePrice(Prices prices)
 {
     return(_animalType.CalculatePrice(Weight, prices));
 }