/// <summary> /// Run starts the menu loop /// </summary> public override void Run() { while (true) { Console.Clear(); Console.WriteLine(this.Title); Console.WriteLine(new string('=', this.Title.Length)); Vendo_Matic_800.DisplayInventory(); Console.WriteLine(new string('=', this.Title.Length)); foreach (KeyValuePair <string, string> menuItem in menuOptions) { Console.WriteLine($"({menuItem.Key}) - {menuItem.Value}"); } string choice = GetString("Selection:").ToUpper(); if (menuOptions.ContainsKey(choice)) { if (!ExecuteSelection(choice)) { //Console.WriteLine("Please choose (1) or (M)!"); //Pause("Press [ENTER] to continue."); break; } } else { Pause("Select [1] or [M],"); } } }
/// <summary> /// Run starts the menu loop /// </summary> public override void Run() { while (true) { Console.Clear(); Console.WriteLine(this.Title); Console.WriteLine(new string('=', this.Title.Length)); Vendo_Matic_800.DisplayInventory(); Console.WriteLine(new string('=', this.Title.Length)); foreach (KeyValuePair <string, string> menuItem in menuOptions) { Console.WriteLine($"({menuItem.Key}) - {menuItem.Value}"); } Console.WriteLine(new string('=', this.Title.Length)); Console.WriteLine($"Current Funds Available: {Vendo_Matic_800.Balance:C}"); Console.WriteLine(new string('=', this.Title.Length)); string choice = GetString("Selection:"); if ((!menuOptions.ContainsKey(choice)) && (!Vendo_Matic_800.vendingStock.ContainsKey(choice))) { Pause("Invalid Input,"); } else if (!ExecuteSelection(choice)) { break; } } }
//public VendingMachine Vendo_Matic_800 { get; set; } /// <summary> /// The override of ExecuteSelection handles whatever selection was made by the user. /// This is where any business logic is executed. /// </summary> /// <param name="choice">"Key" of the user's menu selection</param> /// <returns></returns> protected override bool ExecuteSelection(string choice) { switch (choice) { case "1": ItemsMenu itemsMenu = new ItemsMenu(Vendo_Matic_800); itemsMenu.Run(); return(true); case "2": PurchaseMenu purchaseMenu = new PurchaseMenu(Vendo_Matic_800); purchaseMenu.Run(); return(true); case "E": Console.Clear(); Console.WriteLine($"***** Thank you for using the Vendo-Matic-800!!! *****"); Console.WriteLine(); Vendo_Matic_800.quarters = 0; Vendo_Matic_800.dimes = 0; Vendo_Matic_800.nickels = 0; Vendo_Matic_800.EndVending(); string changeString = $"Please take your change: {Vendo_Matic_800.quarters} Quarters, {Vendo_Matic_800.dimes} Dimes, {Vendo_Matic_800.nickels} Nickels."; Console.WriteLine(new string('=', changeString.Length)); Console.WriteLine(changeString); Console.WriteLine(new string('=', changeString.Length)); Console.WriteLine(); Console.WriteLine("Press [ENTER] to continue!"); Console.ReadLine(); Environment.Exit(0); return(false); case "4": Vendo_Matic_800.GenerateSalesReport(); return(true); } return(true); }
//public VendingMachine Vendo_Matic_800 { get; set; } /// <summary> /// The override of ExecuteSelection handles whatever selection was made by the user. /// This is where any business logic is executed. /// </summary> /// <param name="choice">"Key" of the user's menu selection</param> /// <returns></returns> protected override bool ExecuteSelection(string choice) { switch (choice) { case "1": Console.Clear(); string titleDisplay = $" ************ Your current balance is {Vendo_Matic_800.Balance:C} ************ "; Console.WriteLine(); Console.WriteLine(titleDisplay); Console.WriteLine(new string('=', titleDisplay.Length)); Console.WriteLine(); decimal moneyFeed = GetDecimal("Enter whole dollar amount to deposit or press [ENTER] to return to menu: "); Vendo_Matic_800.Deposit(moneyFeed); if (moneyFeed > 10000000) { Console.Clear(); string tooBigWarning = "!!!! Deposit Amount Exceeds Inventory Value !!!!"; Console.WriteLine(new string('=', tooBigWarning.Length)); Console.WriteLine(tooBigWarning); Console.WriteLine(new string('=', tooBigWarning.Length)); Console.WriteLine(); Console.WriteLine("Press [ENTER] to return to the menu"); Console.ReadLine(); } else if (moneyFeed <= 0) { Console.WriteLine("Please enter a positive whole dollar amount, Press Enter to Continue"); Console.ReadLine(); } Console.Clear(); string titleDisplayNewBalance = $" ************ Your current balance is {Vendo_Matic_800.Balance:C} ************ "; Console.WriteLine(); Console.WriteLine(titleDisplayNewBalance); Console.WriteLine(new string('=', titleDisplayNewBalance.Length)); Console.WriteLine(); Console.WriteLine("Press [ENTER] to return to the Purchase Menu"); Console.ReadLine(); return(true); case "2": ItemSelection itemSelection = new ItemSelection(Vendo_Matic_800); itemSelection.Run(); return(true); case "F": Console.Clear(); Console.WriteLine($"***** Thank you for using the Vendo-Matic-800!!! *****"); Console.WriteLine(); Vendo_Matic_800.quarters = 0; Vendo_Matic_800.dimes = 0; Vendo_Matic_800.nickels = 0; Vendo_Matic_800.EndVending(); string changeString = $"Please take your change: {Vendo_Matic_800.quarters} Quarters, {Vendo_Matic_800.dimes} Dimes, {Vendo_Matic_800.nickels} Nickels."; Console.WriteLine(new string('=', changeString.Length)); Console.WriteLine(changeString); Console.WriteLine(new string('=', changeString.Length)); Console.WriteLine(); Console.WriteLine("Press [ENTER] to continue!"); Console.ReadLine(); MainMenu mainMenu = new MainMenu(Vendo_Matic_800); mainMenu.Run(); return(true); case "M": MainMenu mainMenu2 = new MainMenu(Vendo_Matic_800); mainMenu2.Run(); return(true); //return false; } return(true); }
/// <summary> /// Accepts user intput, makes it readable regardless of case, then decides the next course of action based on the user's choice. /// </summary> /// <param name="message"></param> /// <returns></returns> protected override string GetString(string message) { while (true) { Console.Write(message + " "); string userInput = Console.ReadLine().Trim().ToUpper(); if (!String.IsNullOrEmpty(userInput)) { foreach (Slots slot in Vendo_Matic_800.slotList) { string itemID = slot.SlotID; int itemAmountAvailable = slot.Amount; string itemName = Vendo_Matic_800.vendingStock[itemID].Name; decimal itemPrice = Vendo_Matic_800.vendingStock[itemID].Price; if (userInput == itemID && Vendo_Matic_800.Balance >= itemPrice) { if (slot.Amount >= 1) { Console.Clear(); string dispenseString = $"Dispensing: {Vendo_Matic_800.vendingStock[slot.SlotID].Name} | {Vendo_Matic_800.vendingStock[slot.SlotID].Price:C} has been deducted from your balance."; Console.WriteLine(new string('=', dispenseString.Length)); Vendo_Matic_800.Spend(itemPrice); Vendo_Matic_800.Dispense(slot); Console.WriteLine(dispenseString); Console.WriteLine(); Console.WriteLine($"{Vendo_Matic_800.vendingStock[slot.SlotID].Message}"); Console.WriteLine(); Console.WriteLine($"Your new Balance is: {Vendo_Matic_800.Balance:C}"); Console.WriteLine(new string('=', dispenseString.Length)); } if (itemAmountAvailable < 1) { Console.Clear(); string soldOutString = $"!!!!!!!!!!!!!!!!!! SOLD OUT !!!!!!!!!!!!!!!!!!"; Console.WriteLine(new string('=', soldOutString.Length)); Console.WriteLine(soldOutString); Console.WriteLine(new string('=', soldOutString.Length)); Vendo_Matic_800.Deposit(itemPrice); Pause("Please make another selection,"); break; } Pause("Thank you for your purchase,"); PurchaseMenu purchaseMenu = new PurchaseMenu(Vendo_Matic_800); purchaseMenu.Run(); } else if (userInput == itemID) { Console.Clear(); Vendo_Matic_800.Spend(itemPrice); Pause("Tough Luck!,"); PurchaseMenu purchaseMenu = new PurchaseMenu(Vendo_Matic_800); purchaseMenu.Run(); } } return(userInput); } else { return("!!! Invalid input. Please enter a valid decimal number."); } } }