예제 #1
0
        public int ComputeCost(String drink, bool student, int amount)
        {
            if (!menu.ContainsKey(drink))
            {
                throw new Exception("No such drink exists");
            }

            IBeverage beverage = menu[drink];

            if (amount > MAX_NUMBER_OF_DRINKS && beverage.isAmountLimited())
            {
                throw new Exception("Too many drinks, max " + MAX_NUMBER_OF_DRINKS);
            }

            int price = beverage.GetPrice();

            if (student && beverage.isEligableForStudentDiscount())
            {
                price = price - price / STUDENT_DISCOUNT;
            }

            return(price * amount);
        }