Пример #1
0
 private static void displayPromoInfoToConsole(GroceryItemData item, IPromotion promoInfo)
 {
     if (promoInfo.getQuantityToGetPromoPrice() == 1)
     {
         Console.WriteLine(item.Name + " \t" + MoneyDisplayUtil.formatMoneyDisplay(promoInfo.getTotalPriceForQuantityMet()));
     }
     else
     {
         Console.WriteLine(item.Name + " (X" + promoInfo.getQuantityToGetPromoPrice() + ") " + MoneyDisplayUtil.formatMoneyDisplay(promoInfo.getTotalPriceForQuantityMet()));
     }
     Console.WriteLine("\t" + item.PromotionInfo.getPromoDisplayInfo());
     Console.WriteLine("\tsavings " + MoneyDisplayUtil.formatMoneyDisplay(item.PromotionInfo.getSavings()));
 }
Пример #2
0
 private static void printToConsole(ShoppingBasket shoppingBasket)
 {
     Console.WriteLine("\nReceipt ");
     foreach (GroceryItemData item in shoppingBasket.getShoppingBasket())
     {
         int amount = item.Count;
         while (amount > 0)
         {
             if (item.isOnPromotion && item.PromotionInfo.isMetPromoRequirements(amount))
             {
                 IPromotion promoInfo = item.PromotionInfo;
                 displayPromoInfoToConsole(item, promoInfo);
                 amount -= promoInfo.getQuantityToGetPromoPrice();
             }
             else if (amount > 1)
             {
                 displayMultipleRegularPricedItem(item);
                 amount -= item.Count;
             }
             else
             {
                 Console.WriteLine(item.Name + "\t" + MoneyDisplayUtil.formatMoneyDisplay(item.RegularPrice));
                 amount -= 1;
             }
         }
     }
     Console.WriteLine("--------------------------");
     Console.WriteLine("Total Savings = " + MoneyDisplayUtil.formatMoneyDisplay(shoppingBasket.calculateTotalSavings()));
     Console.WriteLine("Total Due = " + MoneyDisplayUtil.formatMoneyDisplay(shoppingBasket.calculateFinalBill()));
 }
Пример #3
0
        public decimal getTotalCost()
        {
            decimal totalCost = 0;
            int     amount    = _count;

            while (amount > 0)
            {
                if (_isOnPromotion && _promotionInfo.isMetPromoRequirements(amount))
                {
                    totalCost += _promotionInfo.getTotalPriceForQuantityMet();
                    amount    -= _promotionInfo.getQuantityToGetPromoPrice();
                }
                else
                {
                    totalCost += _regularPrice;
                    amount    -= 1;
                }
            }
            return(totalCost);
        }