public static string GrossSummary(string item, int quantity, decimal price) { if (quantity == 0) { return($"There are no {item} in the basket"); } else { return($"{item}: {quantity} @ {price:C}. The gross cost is { CheckoutHelpers.UpdateTotal(quantity, price):C} (before discounts are applied)"); } }
static void Main() { decimal total = 0; //List<string> shoppingBasket = new List<string>(new string[] { "Apple", "Apple", "Apple" }); var shoppingBasket = ShoppingBasketHelpers.GenerateRamdomShoppingBasket(7); Console.WriteLine(StringHelpers.BasketSummary(shoppingBasket)); var totalApples = ShoppingBasketHelpers.GetItemCount(shoppingBasket, @"\b(apple)\b"); try { total = total + CheckoutHelpers.UpdateTotal(totalApples, applePricePerUnit, Discounts.BuyOneGetOneFree); Console.WriteLine(StringHelpers.GrossSummary("Apples", totalApples, applePricePerUnit)); } catch { Console.WriteLine("An error occurred"); return; } var totalOranges = ShoppingBasketHelpers.GetItemCount(shoppingBasket, @"\b(orange)\b"); try { Console.WriteLine(StringHelpers.GrossSummary("Oranges", totalOranges, orangePricePerUnit)); total = total + CheckoutHelpers.UpdateTotal(totalOranges, orangePricePerUnit, Discounts.BuyThreeForTwo); } catch { Console.WriteLine("An error occurred"); return; } Console.WriteLine(); Console.WriteLine(String.Format("The total cost after discounts is {0:C}", total)); Console.ReadLine(); }