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); } }
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); }
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; } } }
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(); }