public bool BuildOrder() { Console.WriteLine("[0] Order Pizza\n[1] Confirm order and Pay\n[2] Preview Order\n[3] Logout/Cancel order"); int select; string input = Console.ReadLine(); if (int.TryParse(input, out select)) { if (select == 0) { APizza thePizza = AddPizza(); if (thePizza == null) { return(true); } if (this.TotalCost + thePizza.Cost > 250) { Console.WriteLine("Your order can't exceed $250. Please try again."); BuildOrder(); } else { this.TotalCost += thePizza.Cost; MyPizzas.Add(thePizza); BuildOrder(); } } else if (select == 1) { ConfirmOrder(); } else if (select == 2) { PreviewOrder(); BuildOrder(); } else if (select != 3) { Console.WriteLine("Please try again"); BuildOrder(); } } else { Console.WriteLine("Please try again"); BuildOrder(); } return(true); }
public void Total() { if (MyPizzas.Count > 0) { Console.WriteLine("\n"); int index = 0; foreach (var p in MyPizzas) { subtotal += MyPizzas[index].Price; Console.WriteLine($"Pizza {index+1}, Price {MyPizzas.First().Price:C}"); for (int i = 0; i < p.MyPizzaToppings.Count; i++) { Console.WriteLine($"\tTopping {p.MyPizzaToppings[i].name}, Price {p.MyPizzaToppings[i].price:C}"); subtotal += p.MyPizzaToppings[i].price; } index++; } } if (MyBurgers.Count > 0) { Console.WriteLine("\n"); int index = 0; foreach (var b in MyBurgers) { Console.WriteLine($"Burger {index + 1}, Price {MyBurgers.First().Price:C}"); subtotal += MyBurgers[index].Price; for (int i = 0; i < b.MyBurgerToppings.Count; i++) { Console.WriteLine($"\tTopping {b.MyBurgerToppings[i].name}, Price {b.MyBurgerToppings[i].price:C}"); subtotal += b.MyBurgerToppings[i].price; } index++; } } if (MyExtras.Count > 0) { Console.WriteLine("\nExtras"); var fries = MyExtras.Where(f => f.Item == "Fries") .GroupBy(s => s.Size) .Select(grp => new { Size = grp.Key, Quantity = grp.Count() }); if (fries.Count() > 0) { foreach (var f in fries) { var price = MyExtras.Where(ms => ms.Size == f.Size && ms.Item == "Fries") .Select(p => p.Price).Distinct().First(); Console.WriteLine($"({f.Quantity}) {f.Size} fries {(price * f.Quantity):C}"); subtotal += price * f.Quantity; } } var drinks = MyExtras.Where(d => d.Item == "Drink") .GroupBy(s => s.Size) .Select(grp => new { Size = grp.Key, Quantity = grp.Count() }); if (drinks.Count() > 0) { foreach (var d in drinks) { var price = MyExtras.Where(ms => ms.Size == d.Size && ms.Item == "Drink") .Select(p => p.Price).Distinct().First(); Console.WriteLine($"({d.Quantity}) {d.Size} drinks {(price * d.Quantity):C}"); subtotal += price * d.Quantity; } } } Console.WriteLine($"\nYour subtotal is {subtotal:C}"); Console.WriteLine($"5.3% sales tax: {subtotal*(5.3m/100m):C}"); Console.WriteLine($"Total: {subtotal*(5.3m/100m) + subtotal:C}"); }
public void AddPizza(APizza pizza) { MyPizzas.Add(pizza); }