/// <summary> /// The product menu for drinks /// </summary> public void ProductDrinks(int totalMoney, InsertMoney Change, AffordProducts afford, List <IProducts> Products, List <IProducts> ProductsValidation, Drinks CocaCola, Drinks Pepsi, Drinks Fanta) { Console.Clear(); Program.DisplayMessage("\nIt would seem you picked drinks! You must be thirsty!", ConsoleColor.Green); bool stayAlive = true; foreach (int value in Change.money) { totalMoney = totalMoney + value; } while (stayAlive) { Program.DisplayMessage("\nHere's youll get a list of drinks that's currently available. Please pick one"); Program.DisplayMessage("\n(You select a drink by writing the first letter of the product you want)\n", ConsoleColor.Yellow); Program.DisplayMessage( $"You currently have {totalMoney} remaining to spend \nX - Go back. " + $"\nZ - remaining change back.\n" ); foreach (IProducts item in Products) { if (item is Drinks) { item.ProductsInfo(); } } char choiceDrinks = char.ToUpper(Console.ReadKey(true).KeyChar); switch (choiceDrinks) { case 'C': ProductsValidation.Add(CocaCola); totalMoney = afford.AffordProduct(totalMoney, ProductsValidation, Change); break; case 'P': ProductsValidation.Add(Pepsi); totalMoney = afford.AffordProduct(totalMoney, ProductsValidation, Change); break; case 'F': ProductsValidation.Add(Fanta); totalMoney = afford.AffordProduct(totalMoney, ProductsValidation, Change); break; case 'X': stayAlive = false; break; case 'Z': Console.Clear(); MoneyBack.MoneyBackCalculation(Change); stayAlive = false; break; default: Program.DisplayMessage("Invalid keypress, please try again", ConsoleColor.Red); break; } ProductsValidation.Clear(); if (stayAlive == true) { Console.ReadKey(true); } Console.Clear(); } }
/// <summary> /// Main menu for the entire Assignment. /// </summary> public int UserMenu() { bool stayAlive = true; int usefulNumber = 0; InsertMoney change = new InsertMoney(); VendingMachine Machine = new VendingMachine(); do { try { Program.DisplayMessage( "\nPlease select a option:\n" + "1: To insert money to the vending machine\n" + "2: To look at the vending machines content\n" + "3: To get your change back and exit the machine\n" + "4: To exit the vending machine without getting your change back\n" ); int choice = int.Parse(Console.ReadLine()); Console.Clear(); switch (choice) { case 1: change.Insert(); break; case 2: Machine.VendingMachinery(change); break; case 3: stayAlive = false; MoneyBack.MoneyBackCalculation(change); break; case 4: stayAlive = false; break; default: throw new Exception(); } } catch (FormatException) { Program.DisplayMessage("Please type a valid number!", ConsoleColor.Red); } catch (OverflowException) { Program.DisplayMessage("Please type a value between 1-3", ConsoleColor.Red); } catch (ArgumentNullException) { Program.DisplayMessage("Please try again", ConsoleColor.Red); } } while (stayAlive); return(usefulNumber); }