Ejemplo n.º 1
0
        public static int CalculateDiscount(RecipeLineItem[] input)
        {
            float regularPrice = 0.0f;
            float discountedPrice = 0.0f;

            foreach (RecipeLineItem rli in input)
            {
                regularPrice += CalculateIngredientExtendedPrice((float)rli.Ingredient.Cost, rli.Units);
                discountedPrice += CalculateIngredientExtendedPrice(CalculateIngredientDiscountedPrice(rli.Ingredient), rli.Units);
            }

            return (int)Math.Round(regularPrice - discountedPrice, MidpointRounding.AwayFromZero);
        }
Ejemplo n.º 2
0
        public static int CalculateTax(RecipeLineItem[] input)
        {
            int output = 0;

            foreach (RecipeLineItem rli in input)
            {
                float extendedPrice = CalculateIngredientExtendedPrice(CalculateIngredientDiscountedPrice(rli.Ingredient), rli.Units);
                int tax = CalculateIngredientTax(rli.Ingredient, extendedPrice);

                output += tax;
            }

            return output;
        }
Ejemplo n.º 3
0
        public static int CalculateTotal(RecipeLineItem[] input)
        {
            float totalPrice = 0.0f;
            int tax = 0;

            foreach (RecipeLineItem rli in input)
            {
                float extendedPrice = CalculateIngredientExtendedPrice(CalculateIngredientDiscountedPrice(rli.Ingredient), rli.Units);
                tax += CalculateIngredientTax(rli.Ingredient, extendedPrice);
                totalPrice += extendedPrice;
            }

            return tax + (int)Math.Round(totalPrice, MidpointRounding.AwayFromZero);
        }