Example #1
0
 public void ClearSelectionsPayments()
 {
     while (productCodes.Count > 0)
     {
         productCodes.Remove(productCodes[0]);
     }
     userPayment = "Q";
     vm.AddMoney(userPayment);
     amountPaid = "";
     amountDue  = "";
 }
        private void FeedMoney()
        {
            Console.Clear();
            Console.WriteLine($"Your total balance is: {_vendingMachine.Balance}");
            Console.WriteLine();
            Console.WriteLine("How much money would you like to add? (Enter whole dollar amounts only up to 20 dollars at a time)");
            decimal moneyAdded = 0;

            try
            {
                moneyAdded = decimal.Parse(Console.ReadLine());
            }
            catch (OverflowException)
            {
            }
            catch (FormatException)
            {
            }
            if (_vendingMachine.VerifyMoneyAdded(moneyAdded))
            {
                Console.Clear();
                _vendingMachine.AddMoney(moneyAdded);
                Console.WriteLine($"Your balance is ${ _vendingMachine.Balance}");
                Console.WriteLine();
                Console.Write("Press any to return to Purchase Items menu. ");
                Console.ReadKey();
                Console.Clear();
            }
            else
            {
                Console.WriteLine("Invalid amount, press any key to continue");
                Console.ReadKey();
            }
        }
Example #3
0
        private void FeedMoney()
        { //if 1 is chosen from submenu
            bool doneWithMoney = false;

            try
            {
                while (!doneWithMoney)
                {
                    Console.WriteLine("Please enter $(1), $(2), $(5), or $(10) bills.");
                    int userInput = Int32.Parse(Console.ReadLine());
                    if (userInput == 1 || userInput == 2 || userInput == 5 || userInput == 10)
                    {
                        vendingMachine.AddMoney(userInput);
                        Console.WriteLine($"You currently have ${vendingMachine.UserMoney()}");
                        vendingMachine.WriteLog($"{DateTime.Now} FEED MONEY: ${userInput} ${vendingMachine.UserMoney()}");
                        Console.WriteLine("Would you like to add more money?(y)(n)");
                        string moreUserInput = Console.ReadLine();
                        if (moreUserInput == "n")
                        {
                            doneWithMoney = true;
                            ItemSelection();
                        }
                        else if (moreUserInput == "y")
                        {
                        }
                        else
                        {
                            doneWithMoney = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Please enter a valid amount.");
                    }
                }
            }
            catch (Exception ex)
            {
                doneWithMoney = true;
            }
        }
        public decimal MoneyFeed()
        {
            Console.WriteLine("How much money in whole dollars would you like to add?");
            decimal dollarAmount = decimal.Parse(Console.ReadLine());
            bool    isValid      = false;

            while (!isValid)
            {
                if (dollarAmount % 1 == 0)
                {
                    vm.AddMoney(dollarAmount);
                    isValid = true;
                }
                else
                {
                    Console.WriteLine("Please enter a valid, whole amount");
                    dollarAmount = decimal.Parse(Console.ReadLine());
                }
            }
            return(vm.Balance);
        }
Example #5
0
        public void Display()
        {
            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("(1) Feed Money");
                Console.WriteLine("(2) Select Product");
                Console.WriteLine("(3) Finish Transaction");
                Console.WriteLine("Current Money Provided: $" + vm.Balance);

                string userInput = Console.ReadLine();

                if (userInput == "1")
                {
                    Console.WriteLine("Please enter $1, $2, $5, or $10: "); //How to handle if entered with $?
                    Decimal.TryParse(Console.ReadLine(), out decimal cash);
                    if (cash == 1.00M || cash == 2.00M || cash == 5.00M || cash == 10.00M)
                    {
                        Console.WriteLine("Money Provided: $" + cash);
                        vm.AddMoney(cash);
                        Console.WriteLine("Your new balance is: $" + vm.Balance);
                    }
                    else
                    {
                        Console.WriteLine("Sorry, that's an invalid amount.");
                    }
                }
                else if (userInput == "2")
                {
                    Console.WriteLine("Please enter your selection: ");
                    string input = (Console.ReadLine()).ToUpper();

                    if (!vm.IsValidSlot(input))
                    {
                        Console.WriteLine("Invalid product code. Please try again.");
                    }
                    else if (!vm.IsInStock(input))
                    {
                        Console.WriteLine("Sorry, item is sold out");
                    }

                    else
                    {
                        VendingItem userDesiredProduct = vm.GetItemAtSlot(input);
                        decimal     cost = userDesiredProduct.Cost;

                        if (vm.Balance < cost)
                        {
                            Console.WriteLine("Please provide more cash");
                        }
                        else
                        {
                            boughtItems.Add(vm.BuyItem(input));
                            Console.WriteLine("Dispensing...");
                            Console.WriteLine("Current Balance: $" + vm.Balance);
                        }
                    }
                }
                else if (userInput == "3")
                {
                    Console.WriteLine("Current Balance: $" + vm.Balance);
                    Console.WriteLine("Your change is " + vm.ReturnChange());
                    foreach (VendingItem item in boughtItems)
                    {
                        Console.WriteLine("Consuming item(s): " + item.MakeEatNoise());
                    }
                    boughtItems.Clear();
                }
                else
                {
                    Console.WriteLine("Please try again.");
                }
            }
        }
        public void RunInterface()
        {
            if (vendingMachine.ReadError != "")
            {
                Console.WriteLine(vendingMachine.ReadError);
                Console.WriteLine("Please exit the vending machine and call Customer Support");
                Console.WriteLine();
            }

            bool done = false;

            while (!done)
            {
                // Top Level Menu
                Console.Clear();
                PrintHeader();
                Console.WriteLine("Main Menu");
                Console.WriteLine("==========================================");
                Console.WriteLine("(1) Display Vending Machine Items");
                Console.WriteLine("(2) Purchase");
                Console.WriteLine("(3) End");

                string mainInput = Console.ReadLine();
                Console.WriteLine();

                switch (mainInput)
                {
                case "1":
                    Display();     // Display list of all items with slot, name, and price
                    Console.WriteLine("Press any key to continue.");
                    Console.ReadKey();
                    break;

                case "2":
                    Purchase();     // Progress to purchasing menu
                    break;

                case "3":
                    done = true;     // Exit vending machine
                    break;

                case "9":
                    vendingMachine.SalesReport();     // Hidden selection, run sales report

                    if (vendingMachine.WriteError != "")
                    {
                        Console.WriteLine(vendingMachine.WriteError);
                        Console.WriteLine("Please exit the vending machine and call Customer Support");
                        Console.WriteLine();
                    }

                    break;

                default:
                    Console.WriteLine("Please enter a valid selection.");
                    Console.WriteLine();
                    break;
                }

                void Display() // Display list of all snack items
                {
                    Console.Clear();
                    PrintHeader();
                    Console.WriteLine(" Slot | Snack Item          | Price | Qty ");
                    Console.WriteLine("==========================================");
                    foreach (VendingMachineItem item in vendingMachine.items)
                    {
                        Console.Write($"  {item.Slot}   ");
                        Console.Write($" {item.Name}".PadRight(22));
                        Console.Write($" ${item.Price}".PadRight(7));
                        if (item.Stock == 0)
                        {
                            Console.WriteLine("  OUT OF STOCK");
                        }
                        else
                        {
                            Console.WriteLine($"   {item.Stock}");
                        }
                    }
                    Console.WriteLine("==========================================");
                    Console.WriteLine();

                    return;
                }

                void Purchase() // Purchase an item from the machine
                {
                    bool purchase = true;

                    while (purchase)
                    {
                        Console.Clear();
                        PrintHeader();
                        Console.WriteLine("Purchase Menu");
                        Console.WriteLine("==========================================");
                        Console.WriteLine("(1) Feed Money");
                        Console.WriteLine("(2) Select Product");
                        Console.WriteLine("(3) Finish Transaction");

                        Console.WriteLine();
                        Console.WriteLine($"Current Balance: ${vendingMachine.Balance}");


                        string purchaseInput = Console.ReadLine();
                        Console.WriteLine();


                        switch (purchaseInput)
                        {
                        case "1":     // Ya pays your money and ya takes yer chances
                            bool feeding = true;
                            while (feeding)
                            {
                                Console.Clear();
                                PrintHeader();
                                Console.WriteLine("How much would you like to add?");
                                Console.WriteLine("1) $1 ");
                                Console.WriteLine("2) $2 ");
                                Console.WriteLine("3) $5 ");
                                Console.WriteLine("4) $10 ");
                                Console.WriteLine("5) Return to Purchase Menu");
                                Console.WriteLine();
                                Console.WriteLine($"Current Balance: ${vendingMachine.Balance}");

                                string addedMoney = Console.ReadLine();
                                Console.WriteLine();

                                switch (addedMoney)     // Add various whole-dollar denominations
                                {
                                case "1":
                                    vendingMachine.AddMoney(1);
                                    break;

                                case "2":
                                    vendingMachine.AddMoney(2);
                                    break;

                                case "3":
                                    vendingMachine.AddMoney(5);
                                    break;

                                case "4":
                                    vendingMachine.AddMoney(10);
                                    break;

                                case "5":         // Exit Feed Money menu, return to Purchase menu
                                    feeding = false;
                                    break;

                                default:
                                    Console.WriteLine("Please enter a valid amount");
                                    Console.WriteLine();
                                    break;
                                }

                                if (vendingMachine.WriteError != "")
                                {
                                    Console.WriteLine(vendingMachine.WriteError);
                                    Console.WriteLine("Please exit the vending machine and call Customer Support");
                                    Console.WriteLine();
                                }
                            }

                            break;

                        case "2":
                            Display();     // Select snack item
                            Console.WriteLine("Please enter a valid slot number to purchase the item");
                            string slot = Console.ReadLine().ToUpper();

                            Console.WriteLine(vendingMachine.Purchase(slot));
                            Console.WriteLine();
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();

                            if (vendingMachine.WriteError != "")
                            {
                                Console.WriteLine(vendingMachine.WriteError);
                                Console.WriteLine("Please exit the vending machine and call Customer Support");
                                Console.WriteLine();
                            }

                            break;

                        case "3":     // Exit transaction, receive change, return to top menu
                            Console.WriteLine(vendingMachine.MakeChange());
                            Console.WriteLine();
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();

                            if (vendingMachine.WriteError != "")
                            {
                                Console.WriteLine(vendingMachine.WriteError);
                                Console.WriteLine("Please exit the vending machine and call Customer Support");
                                Console.WriteLine();
                            }

                            purchase = false;
                            break;

                        default:
                            Console.WriteLine("Please enter a valid selection.");
                            Console.WriteLine();
                            break;
                        }
                    }
                }
            }
        }