/// <summary> /// -Asks the user to input a whole dollar amount (int dollars). /// -Then adds that integer input to CurrentBalance(VendingMachine Class property). /// </summary> /// <param name="dollars"></param> public void FeedMoney(int dollars) { if (dollars > 0) { CurrentBalance += dollars; } else { throw new Exception("Please enter a dollar amount greater than 0."); } _transactionFileLogger.RecordDeposit(dollars, CurrentBalance); }
/// <summary> /// /// </summary> /// <param name="dollars"></param> public void FeedMoney(int dollars) { //string directory = Environment.CurrentDirectory; //string filePath = "Log.txt"; //string fullPath = Path.Combine(directory, filePath); if (dollars > 0) { CurrentBalance += dollars; } else { throw new Exception("Please enter a dollar amount greater than 0."); } _transactionFileLogger.RecordDeposit(dollars, CurrentBalance); //using (StreamWriter sw = new StreamWriter(fullPath, true)) //{ // sw.WriteLine("{0,-10}{1,-10}{2,-10}{3,-10}", $"{DateTime.Now}", " FEED MONEY:", $" ${dollars}", $" ${CurrentBalance}"); //} }
private void DisplayPurchaseMenu() { while (true) { Console.WriteLine("Please Choose Below"); Console.WriteLine("1) Feed Money"); Console.WriteLine("2) Select Product"); Console.WriteLine("3) Finish Transaction"); string inputTwo = Console.ReadLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); if (inputTwo == "1") { Console.WriteLine("Please enter amount in 1's, 5's, 10's or 20's"); string money = Console.ReadLine(); decimal record = Convert.ToDecimal(money); vendomatic.FeedMoney(int.Parse(money)); Console.WriteLine("Current balance is $" + vendomatic.CurrentBalance); log.RecordDeposit(record, vendomatic.CurrentBalance); } else if (inputTwo == "2") { Console.WriteLine("Enter selected product code"); string userSelection = Console.ReadLine(); try { ItemGeneral purchasedItem = vendomatic.Purchase(userSelection); itemsBought.Add(purchasedItem); Console.WriteLine($"Here is your {purchasedItem.Name} and current balance is " + vendomatic.CurrentBalance); log.RecordPurchase(purchasedItem.Name, userSelection, vendomatic.CurrentBalance, vendomatic.CurrentBalance - purchasedItem.Cost); } catch (VendingMachineException ex) { Console.WriteLine(ex.Message); } } else if (inputTwo == "3") { Change coins = vendomatic.ReturnChange(); log.RecordFinalChange(vendomatic.CurrentBalance); for (int i = 0; i < itemsBought.Count; i++) { Console.WriteLine(itemsBought[i].Consume()); } Console.WriteLine("Your money back is:"); Console.WriteLine("In Quarters " + coins.Quarters); Console.WriteLine("In Dimes " + coins.Dimes); Console.WriteLine("In Nickles " + coins.Nickels); Console.WriteLine("Current Vendo Matic Balace is " + vendomatic.CurrentBalance); break; } } }
public void DisplayPurchaseMenu() { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Purchase Menu"); Console.WriteLine(); Console.WriteLine("(1) Feed Money"); Console.WriteLine("(2) Select Product"); Console.WriteLine("(3) Finish Transaction"); Console.WriteLine("(M) Main Menu"); Console.WriteLine($"Current Money Provided: {vm.CurrentBalance.ToString("C")}"); Console.Write("Please select an option: "); option_DisplayPurchaseMenu = Console.ReadLine(); Console.WriteLine(); Console.WriteLine(); while (true) { if (option_DisplayPurchaseMenu == "1") { Console.WriteLine("How much money would you like to deposit?"); Console.WriteLine("(1) $1.00"); Console.WriteLine("(2) $5.00"); Console.WriteLine("(3) $10.00"); Console.WriteLine("(4) $20.00"); option_InsertMoney = Console.ReadLine(); if (option_InsertMoney == "1") { vm.FeedMoney(1); Console.WriteLine($"Current Money Provided: {vm.CurrentBalance.ToString("C")}"); TransactionFileLog feedMoney = new TransactionFileLog("Log.txt"); feedMoney.RecordDeposit(1, vm.CurrentBalance); Console.WriteLine("Would you like to deposit more money (Y/N)? "); string moreMoney = Console.ReadLine().ToUpper(); if (moreMoney == "N") { break; //DisplayPurchaseMenu(); } } else if (option_InsertMoney == "2") { vm.FeedMoney(5); Console.WriteLine($"Current Money Provided: {vm.CurrentBalance.ToString("C")}"); TransactionFileLog feedMoney = new TransactionFileLog("Log.txt"); feedMoney.RecordDeposit(5, vm.CurrentBalance); Console.WriteLine("Would you like to deposit more money (Y/N)? "); string moreMoney = Console.ReadLine().ToUpper(); if (moreMoney == "N") { break; // DisplayPurchaseMenu(); } } else if (option_InsertMoney == "3") { vm.FeedMoney(10); Console.WriteLine($"Current Money Provided: {vm.CurrentBalance.ToString("C")}"); TransactionFileLog feedMoney = new TransactionFileLog("Log.txt"); feedMoney.RecordDeposit(10, vm.CurrentBalance); Console.WriteLine("Would you like to deposit more money (Y/N)? "); string moreMoney = Console.ReadLine().ToUpper(); if (moreMoney == "N") { break; // DisplayPurchaseMenu(); } } else if (option_InsertMoney == "4") { vm.FeedMoney(20); Console.WriteLine($"Current Money Provided: {vm.CurrentBalance.ToString("C")}"); TransactionFileLog feedMoney = new TransactionFileLog("Log.txt"); feedMoney.RecordDeposit(20, vm.CurrentBalance); Console.WriteLine("Would you like to deposit more money (Y/N)? "); string moreMoney = Console.ReadLine().ToUpper(); if (moreMoney == "N") { break; // DisplayPurchaseMenu(); } } else { Console.WriteLine("Please select a valid money option!!"); } } if (option_DisplayPurchaseMenu == "2") { Console.WriteLine("Please select a SlotId to purchase: "); Console.WriteLine(); string[] slots = vm.Slots; for (int i = 0; i < slots.Length; i++) { if (vm.GetQuantityRemaining(slots[i]) < 1) { Console.WriteLine($"{slots[i]} ** SOLD OUT ** {vm.GetItemAtSLot(slots[i]).ItemName} - {vm.GetItemAtSLot(slots[i]).Price.ToString("C")}"); } Console.WriteLine($"{slots[i]} | {vm.GetQuantityRemaining(slots[i].ToString())} - {vm.GetItemAtSLot(slots[i]).ItemName} - {vm.GetItemAtSLot(slots[i]).Price.ToString("C")} "); } Console.WriteLine(); Console.Write("Selection: "); option_MakeSelection = Console.ReadLine(); //consumeList.Add(vm.Purchase(option_MakeSelection)); try { if (vm.GetQuantityRemaining(option_MakeSelection.ToString()) == 0) { throw new OutOfStockException("This item is out of stock, please select again!"); } } catch (OutOfStockException ex) { Console.WriteLine(ex.Message); DisplayPurchaseMenu(); } try { if (!vm.inventory.ContainsKey(option_MakeSelection)) { throw new InvalidSlotIDException("Invalid selection, please try again!"); } } catch (InvalidSlotIDException ex) { Console.WriteLine(ex.Message); DisplayPurchaseMenu(); } try { if (vm.CurrentBalance < vm.GetItemAtSLot(option_MakeSelection).Price) { throw new InsufficientFundsException($"NO {vm.GetItemAtSLot(option_MakeSelection).ItemName} FOR YOU! Give me more money..."); } } catch (InsufficientFundsException ex) { Console.WriteLine(ex.Message); DisplayPurchaseMenu(); } TransactionFileLog feedMoney = new TransactionFileLog("Log.txt"); //would it work best to put after purchase and make currentBalane+vm.GetItemAtSlot feedMoney.RecordPurchase(vm.GetItemAtSLot(option_MakeSelection).ItemName, option_MakeSelection, vm.CurrentBalance, (vm.CurrentBalance - vm.GetItemAtSLot(option_MakeSelection).Price)); vm.Purchase(option_MakeSelection); consumeList.Add(vm.GetItemAtSLot(option_MakeSelection)); Console.WriteLine($"You purchased {vm.GetItemAtSLot(option_MakeSelection).ItemName}! ENJOY!!"); Console.WriteLine($"Current Balance is: {vm.CurrentBalance}"); Console.WriteLine(); Console.WriteLine("Would you like to purchase another item (Y/N)? "); string wantAnotherItem = Console.ReadLine().ToUpper(); if (wantAnotherItem == "N") { break; //DisplayPurchaseMenu(); } } if (option_DisplayPurchaseMenu == "3") { TransactionFileLog feedMoney = new TransactionFileLog("Log.txt"); feedMoney.RecordCompleteTransaction(vm.CurrentBalance); DisplayChange(); vm.ReturnChange(); Console.WriteLine("Your current balance is " + vm.CurrentBalance.ToString("C")); for (int i = 0; i < consumeList.Count; i++) { Console.WriteLine("I'm enjoying my " + consumeList[i].itemName + ", " + consumeList[i].Consume()); ///Cant figure why gum prints GLUG GLUG? } Environment.Exit(0); } if (option_DisplayPurchaseMenu == "M") { break; } } }
private void DisplayPurchaseMenu() { while (true) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(); Console.WriteLine(); Console.WriteLine("==========================================="); Console.WriteLine(" (1) Feed Me, Seymour" + "\n (2) Select Product" + "\n (3) Finish Transaction"); Console.WriteLine("==========================================="); Console.ResetColor(); string input = Console.ReadLine(); if (input == "1") { Console.WriteLine("Please feed money into SnackBot (enter dollars 1 | 2 | 5 | 10)"); string moneyEntered = Console.ReadLine(); if (moneyEntered == "1" || moneyEntered == "2" || moneyEntered == "5" || moneyEntered == "10") { vm.FeedMoney(int.Parse(moneyEntered)); Console.WriteLine("Money added! Treat yo self!"); Console.WriteLine($"You have ${vm.CurrentBalance} to spend!"); logger.RecordDeposit(int.Parse(moneyEntered), vm.CurrentBalance); } else { Console.WriteLine("Hmm, something doesn't look right."); } } if (input == "2") { DisplayInventory(); Console.WriteLine("Please select your item using the slot ID"); string itemToVend = Console.ReadLine().ToUpper(); bool weCanAffordIt; //try //{ // decimal oldBalance = vm.CurrentBalance; // Console.WriteLine($"Thanks for buying {vm.GetItemAtSlot(itemToVend).ItemName} - you have ${vm.CurrentBalance - vm.GetCostOfItem(itemToVend)} left."); // Console.WriteLine(vm.GetItemAtSlot(itemToVend).Consume()); // logger.RecordPurchase(vm.GetItemAtSlot(itemToVend).ItemName, itemToVend, oldBalance, vm.CurrentBalance - vm.GetCostOfItem(itemToVend)); // vm.Purchase(itemToVend); //} //catch (VendingMachineException ex) //{ // Console.WriteLine(ex.Message); // DisplayPurchaseMenu(); //} try { if (!vm.DoesVendingMachineContainSlot(itemToVend)) { throw new InvalidSlotIDException("That Slot ID doesn't exist."); } } catch (InvalidSlotIDException ex) { Console.WriteLine(ex.Message); continue; } try { if (vm.GetQuantityRemaining(itemToVend) == 0) { throw new OutOfStockException("Sorry, that item is sold out!"); } } catch (OutOfStockException ex) { Console.WriteLine(ex.Message); DisplayPurchaseMenu(); } try { weCanAffordIt = vm.GetCostOfItem(itemToVend) <= vm.CurrentBalance; if (!weCanAffordIt) { throw new InsufficientFundsException("Sorry, you can't afford that item. Your balance is: " + vm.CurrentBalance.ToString("C") + "."); } } catch (InsufficientFundsException ex) { Console.WriteLine(ex.Message); DisplayPurchaseMenu(); } decimal oldBalance = vm.CurrentBalance; Console.WriteLine($"Thanks for buying {vm.GetItemAtSlot(itemToVend).ItemName} - you have ${vm.CurrentBalance- vm.GetCostOfItem(itemToVend)} left."); Console.WriteLine(vm.GetItemAtSlot(itemToVend).Consume()); logger.RecordPurchase(vm.GetItemAtSlot(itemToVend).ItemName, itemToVend, oldBalance, vm.CurrentBalance - vm.GetCostOfItem(itemToVend)); vm.Purchase(itemToVend); } if (input == "3") { logger.RecordCompleteTransaction(vm.CurrentBalance); DisplayReturnedChange(); vm.ReturnChange(); Console.WriteLine("Balance is now $0; your change should be printed."); break; } } }
public void Display() { while (true) { Console.WriteLine(); Console.WriteLine("(1) Feed Money"); Console.WriteLine("(2) Select Product"); Console.WriteLine("(3) Finish Transaction"); Console.WriteLine(); string input = Console.ReadLine(); if (input == "1") { try { Console.WriteLine("How many dollars would you like to insert?"); int fedMoney = Int32.Parse(Console.ReadLine()); logger.RecordDeposit(fedMoney, (VM.CurrentBalance + fedMoney)); VM.FeedMoney(fedMoney); } catch (FormatException) { Console.Beep(); Tools.ColorfulWriteLine("Please only enter a whole Dollar Value", ConsoleColor.Red); } } else if (input == "2") { Console.WriteLine("Please select your product."); Console.WriteLine(); string slotId = Console.ReadLine().ToUpper(); VendingMachineItem productSelected = VM.GetItemAtSlot(slotId); if (productSelected != null) { totalProductsSelected.Add(productSelected); logger.RecordPurchase(productSelected.Name, slotId, VM.CurrentBalance, VM.CurrentBalance - productSelected.Price); } } else if (input == "3") { change = VM.returnChange(); Console.WriteLine("Your change is:"); Console.WriteLine(change.Quarters + " in quarters, " + change.Dimes + " in dimes, " + change.Nickels + " in nickels"); Console.WriteLine(); logger.RecordCompleteTransaction(change.TotalChange, VM.CurrentBalance); for (int i = 0; i < totalProductsSelected.Count; i++) { Console.WriteLine(totalProductsSelected[i].Consume()); } break; } else { Console.WriteLine("You did not enter a valid option?"); } Console.WriteLine(VM.CurrentBalance.ToString("C")); } }