예제 #1
0
 public void AddGroceryItem(GroceryItem Item)
 {
     if (_GroceryItemsList.Any(prod => prod.name == Item.name))
     {
         var duplicateItem = _GroceryItemsList.FindLast(prod => prod.name == Item.name);
         duplicateItem.quantity++;
     }
     else
     {
         _GroceryItemsList.Add(Item);
     }
 }
예제 #2
0
        public bool BuyXGetYFree(GroceryItem item)
        {
            //Total everything up
            _Total = TotalGroceryList();

            BuyQuantityForOneFree  = item.BuyXFreeDeal;
            ItemsCalculatedForFree = item.quantity / BuyQuantityForOneFree;

            if (item.quantity >= BuyQuantityForOneFree)
            {
                _Total = (_Total - ItemsCalculatedForFree) * item.price;
                return(true);
            }
            return(false);
        }
예제 #3
0
        public void BuyThreeGetOneFree(GroceryItem Item)
        {
            for (int i = 0; i < _GroceryItemsList.Count; i++)
            {
                var count = i;

                if (count == 2)
                {
                    Item.price = 0.00;
                    Console.WriteLine("Buy 2 get 1 Free");
                }
                else
                {
                    Item.price = Item.regularPrice;
                }
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            //Create a new Grocery List
            var myGroceryList = new GroceryList();

            //Cycle through shopping list and add items
            foreach (var item in args)
            {
                //For every shopping item create new GroceryItem Object
                var GroceryPurchase = new GroceryItem(item);

                //Add GroceryItem to my shopping list
                myGroceryList.AddGroceryItem(GroceryPurchase);
            }

            //Print out my shopping list
            myGroceryList.PrintReceipt();
        }