public static void SelectProductMenu(VendingMachine vendingMachine)
        {
            bool isExit = false;

            while (!isExit)
            {
                Console.Clear();
                Console.WriteLine("Your options are: ");

                Menu.DisplaySlots(vendingMachine.SlotsList());

                Console.WriteLine();
                Console.Write("What would you like to choose? ");
                string userSelection = Console.ReadLine().ToUpper();

                if (vendingMachine.SlotExists(userSelection))
                {
                    string dispensedMessage = vendingMachine.DispenseItem(userSelection);
                    isExit = true;

                    Menu.DisplayMessage(dispensedMessage);
                }
                else if (userSelection == "")
                {
                    isExit = true;
                }
                else
                {
                    Menu.DisplayMessage("Please enter the selection letter and number of the slot for your desired item.");
                }
            }
        }
Example #2
0
 private void PurchaseItem(string menuSelection)
 {
     _vm.DispenseItem(menuSelection);
     MiscUtility.PlaySound(_vm.FetchItemSoundFile(menuSelection));
     Console.WriteLine(_vm.FetchItemNoiseMessage(menuSelection));
     Logging.LogPurchase(menuSelection, _vm);
     Reporting.ReportSale(menuSelection, _vm);
     PressAnyToContinue();
 }
Example #3
0
        //test would create and infinite loop because currentBalance is set through a void method on program.cs
        public decimal UserInput2(decimal currentBalance) //Purchase item
        {
            vendoMatic.DisplayItems();
            Console.WriteLine("Please enter the location code for your item.");
            string enteredItemID = Console.ReadLine().ToUpper();
            Item   selectedItem  = new Item(enteredItemID);

            //check if entered Item ID exists
            if (!selectedItem.ItemExists(enteredItemID))
            {
                Console.WriteLine("You have entered an invalid item code");
            }
            else if (selectedItem.ItemExists(enteredItemID) && vendoMatic.IsOutOfStock(enteredItemID))
            {
                Console.WriteLine("The item you selected is SOLD OUT");
            }
            else if (currentBalance >= selectedItem.ItemPrice) //Purchse Item succesful
            {
                vendoMatic.DispenseItem(enteredItemID, currentBalance);
                currentBalance = currentBalance - selectedItem.ItemPrice;
                //salesReport.UpdateSalesReport(enteredItemID);
                try
                {
                    using (StreamWriter sw = new StreamWriter(outputFile, true))
                    {
                        sw.WriteLine(now.ToString() + $" {selectedItem.ItemName} {selectedItem.ItemID} ${currentBalance + selectedItem.ItemPrice} ${currentBalance}");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("There was an error");
                    Console.WriteLine(e.Message);
                    //return to PurchaseItems menu and rerun
                }
            }
            else if (currentBalance < selectedItem.ItemPrice)
            {
                Console.WriteLine("You do not have enough money to make that purchase. Please input money.");
            }

            return(currentBalance);
        }
Example #4
0
        public void PurchaseMenu(VendingMachine vendingMachine)
        {
            while (true)
            {
                Console.WriteLine("-----TE Vending Machine-----");
                Console.WriteLine("  Powered by Umbrella Corp");
                Console.WriteLine();
                Console.WriteLine("> To Feed Money, press 1: ");
                Console.WriteLine("> To Select Product, press 2: ");
                Console.WriteLine("> To Finish Transaction, press 3: ");
                Console.WriteLine();
                Console.WriteLine($"> Current Money Provided {vendingMachine.Balance:C}");
                Console.WriteLine();
                string input = Console.ReadLine().ToUpper();

                if (input == "1")
                {
                    Console.Write("> How much money would you like to insert, $1, $2, $5, or $10? ");
                    decimal moneyFed = decimal.Parse(Console.ReadLine());

                    decimal[] validAmount = new decimal[4] {
                        1M, 2M, 5M, 10M
                    };

                    if (validAmount.Contains(moneyFed))
                    {
                        vendingMachine.FeedMoney(moneyFed);
                        Console.Clear();
                    }
                    else
                    {
                        Console.WriteLine("That is not a valid amount to deposit. Please try again.");
                        Console.WriteLine();
                    }
                }
                else if (input == "2")
                {
                    Console.Clear();
                    Console.WriteLine("-----TE Vending Machine-----");
                    Console.WriteLine("  Powered by Umbrella Corp");
                    Console.WriteLine();
                    DisplayStock(vendingMachine);
                    Console.Write("> What product would you like to purchase? ");
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine($"> Current Money Provided {vendingMachine.Balance:C}");
                    string productSelection = Console.ReadLine().ToUpper();

                    while (true)
                    {
                        if (!vendingMachine.ValidProductSelection(productSelection))
                        {
                            Console.WriteLine("This is not a valid product choice. Please try again.");
                            Console.WriteLine();
                            break;
                        }
                        else if (!vendingMachine.ProductInStock(productSelection))
                        {
                            Console.WriteLine("This product is currently out of stock. Please select a different product.");
                            Console.WriteLine();
                            break;
                        }
                        else if (!vendingMachine.HasRequiredBalance(productSelection))
                        {
                            Console.WriteLine("You have not inserted enough money to buy this product. Please insert more money or select a different item!");
                            Console.WriteLine();
                            break;
                        }
                        else
                        {
                            Console.WriteLine();
                            Console.WriteLine("Your product is now being dispensed. Thank you!");
                            Console.WriteLine();
                            vendingMachine.DispenseItem(productSelection);
                            break;
                        }
                    }
                }
                else if (input == "3")
                {
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine($"> Your change is... ");
                    Change change = vendingMachine.MakeChange(vendingMachine.Balance);
                    Console.WriteLine($"{change.Quarters} quarters, " +
                                      $"{change.Dimes} dimes, " +
                                      $"and {change.Nickels} nickels.");
                    Console.WriteLine();
                    while (vendingMachine.PurchasedStock.Count > 0)
                    {
                        PurchasableItem item = vendingMachine.PurchasedStock.Dequeue();
                        //vendingMachine.SalesReport(item);
                        Console.WriteLine(item.ConsumeMessage());
                    }
                    Console.WriteLine();
                    Console.WriteLine("> Press any key to continue...");
                    Console.ReadKey();
                    Console.Clear();
                    break;
                }
            }
        }