/// <summary> /// Runs vending machine application in Program; writes out menu to console /// Allows user to select options: /// 1) views an inventory of vending items /// 2) moves user to the Purchase submenu through the PurchaseMenu Run() method /// Q) closes vending machine application /// </summary> #region Run Method public void Run() { bool done = false; while (!done) { DisplayMenu(); char input = Console.ReadKey().KeyChar; try { if (input == '1') { WriteContents(); } else if (input == 'Q' || input == 'q') { done = true; } else if (input == '2') { PurchaseMenu start = new PurchaseMenu(_vMachine); start.Run(); } else { Console.WriteLine("Please enter valid instruction.\nPress any key to try again."); Console.ReadKey(); } } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); } } }
/// <summary> /// Constructor adds items to the top-level menu /// </summary> public MainMenu(string inventoryFilePath) : base() { this.Title = "*** Vendo-Matic 800 ***"; this.menuOptions.Add("1", "Display Vending Machine Items"); this.menuOptions.Add("2", "Purchase"); this.menuOptions.Add("3", "Exit"); this.menuOptions.Add("4", "Sales Report"); vMachine = new VendingMachine(inventoryFilePath); pMenu = new PurchaseMenu(vMachine); }
//Constructor public MainMenu(VendingMachine vendingMachine) { VendingMachine = vendingMachine; PurchaseMenu = new PurchaseMenu(vendingMachine); }