public void EnterPurchaseMenu(VendingMachine vm) { while (true) { DisplayPurchaseMenu(vm); string selection = Console.ReadLine(); switch (selection) { case "1": Console.WriteLine("Enter the amount you would like to add in whole dollars"); string input = Console.ReadLine(); int amt; bool didParseSucceed = int.TryParse(input, out amt); if (!didParseSucceed) { Console.WriteLine("Invalid entry. Please try again."); break; } vm.FeedMoney(amt); break; case "2": vm.DisplayCurrentInventory(); Console.WriteLine("Please enter a selection"); string input1 = Console.ReadLine().ToUpper(); vm.Dispense(input1); break; case "3": Console.WriteLine("Thank you for your patronage!"); (int numQ, int numD, int numN) = ChangeIntoQuarDimNic(vm); Console.WriteLine($"Your change is {numQ} Quarters, {numD} Dimes, and {numN} Nickels."); return; default: break; } Console.WriteLine("Press enter to continue."); Console.ReadLine(); } }
public void Display() { while (true) { Console.WriteLine(); Console.WriteLine("Purchase Menu"); Console.WriteLine("1] >> Feed Money "); Console.WriteLine("2] >> Select Product"); Console.WriteLine("3] >> Finish Transaction"); Console.WriteLine("Q] >> Return to Main Menu"); Console.Write("Please make a selection: "); string input = Console.ReadLine(); if (input == "1") { Console.WriteLine(""); // Feeding Money vm.FeedMoney(vm); Console.Clear(); } else if (input == "2") { Console.WriteLine(""); // Selecting Product (string slotID, bool enoughMoney, bool notSoldOut) = vm.SelectProduct(); if (enoughMoney && slotID != "Q" && notSoldOut) { itemToConsume = vm.CurrentStock[slotID].SlotItem; vm.Dispense(vm, slotID); Console.WriteLine($"{vm.CurrentStock[slotID].SlotItem.ProductName} dispensing now . . ."); System.Threading.Thread.Sleep(3000); } if (!notSoldOut) { Console.WriteLine(); Console.WriteLine("Item is sold out!"); System.Threading.Thread.Sleep(2000); } Console.Clear(); } else if (input == "3") { if (vm.Balance == 0) { Console.WriteLine(); Console.WriteLine("Transaction Cancelled"); Console.WriteLine(); System.Threading.Thread.Sleep(1000); Console.WriteLine($"Returning to main menu now . . ."); System.Threading.Thread.Sleep(2000); Console.Clear(); } else { Console.WriteLine(""); // Finishing Transaction vm.GiveChange(vm); Console.WriteLine(); System.Threading.Thread.Sleep(1500); Customer customer = new Customer(); if (itemToConsume != null) { string result = customer.Consume(itemToConsume.Type); Console.WriteLine(result); Console.WriteLine(); } System.Threading.Thread.Sleep(2000); Console.WriteLine($"Returning to main menu now . . ."); System.Threading.Thread.Sleep(3500); Console.Clear(); } } else if (input.ToUpper() == "Q") { Console.WriteLine("Returning to main menu"); break; } else { Console.WriteLine("Please try again"); } } }
/// <summary> /// dislays menu to select product, shows the same Display() method /// called by the DisplayMenu() /// allows entry of slot ID, then checks validity of entry /// if valid, displays a string telling the user what item they /// purchased, and ascii art of the item type /// also tells user if an item is sold out, if the user is out /// of money, or if selection is invalid /// automatically returns to the previous menu after each input /// </summary> public void SelectProductMenu() { bool exit = false; while (!exit) { Console.Clear(); Console.WriteLine("\n" + _title + "\n"); DisplayItems(); Console.WriteLine("\nEnter Slot ID for the item you would like to purchase: "); string selection = Console.ReadLine(); Item itemPurchased = _vm.Dispense(selection); bool enoughMoney = true; bool productExists = _vm.ProductExists(selection); bool soldOut = _vm.SoldOut(selection); if (!productExists) { Console.WriteLine("Not a valid selection!"); Console.ReadKey(); exit = true; } else { enoughMoney = _vm.MachineBalance >= itemPurchased.Price; } if (productExists && soldOut) { Console.WriteLine("Selection is SOLD OUT."); Console.WriteLine("\nPress any key to return to the Purchase Menu."); Console.ReadKey(); exit = true; } else if (productExists && enoughMoney) { _purchaseList.Add(itemPurchased); _vm.UpdateBalance(selection); itemPurchased.QtyUpdate(); Console.WriteLine($"\n You purchased: {itemPurchased.Name}!!!\n"); Console.WriteLine(itemPurchased.ItemArt()); Console.WriteLine("\n\nPress any key to return to the Purchase Menu."); Console.ReadKey(); exit = true; } else if (productExists && !enoughMoney) { Console.WriteLine("Add more money to machine to purchase this item!"); Console.ReadKey(); exit = true; } } }