protected override bool ExecuteSelection(string choice) { string selection = ""; switch (choice) { case "1": // Feed money option Console.Clear(); Console.WriteLine("*** Feed money ***"); Console.WriteLine($"*** Current balance: {VendOMatic.Balance:C} ***"); Console.WriteLine("1. Add 1¢"); Console.WriteLine("2. Add 5¢"); Console.WriteLine("3. Add 10¢"); Console.WriteLine("4. Add 25¢"); Console.WriteLine("5. Add $1"); Console.WriteLine("6. Add $2"); Console.WriteLine("7. Add $5"); Console.WriteLine("8. Add $10"); Console.WriteLine("Q. Quit"); selection = Console.ReadLine().Trim(); selection = selection.Substring(0, 1).ToUpper(); if (selection != "Q") { this.AddMoney(selection); } Console.WriteLine(); return(true); case "2": // Purchase VendOMatic.ShowContents(); Console.Write("Please enter a slot ID: "); selection = Console.ReadLine().Trim(); this.MakePurchase(selection); return(true); case "3": // Finish transaction // Print out the change we recieve using our change object Console.WriteLine(this.TotalChange.TotalValue(VendOMatic.Balance)); // Restock the vending machine Stocker stocker = new Stocker(); FileLog.Log("GIVE CHANGE", VendOMatic.Balance, 0.0M); VendOMatic.Load(stocker.Restock()); // Eat everything this.Customer.Eat(); Console.ReadKey(); return(false); case "Q": return(false); } // End switch return(true); } // End ExecuteSelection
/// <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>True if we want to stay in the menu loop, false otherwise</returns> protected override bool ExecuteSelection(string choice) { switch (choice) { case "1": // Print out the stock of our vending machine VendOMatic.ShowContents(); Console.ReadKey(); return(true); case "2": // The purchase sub menu { PurchaseMenu purchaseMenu = new PurchaseMenu(); purchaseMenu.Receive(VendOMatic, this.Customer); purchaseMenu.Run(); } return(true); } return(true); }