public void CompleteTransaction(decimal startBal, VendingMachine vendingMachine, List <VendingMachineItem> customer, VendingMachineLogger logger, MainMenu mainmenu)
 {
     if (customer.Count > 0 || vendingMachine.Balance > 0)// if - customer has items to consume and change to be returned, perform appropriate actions
     {
         Console.WriteLine();
         foreach (var item in customer)// loop through purchased items and 'cosume' them
         {
             Console.WriteLine(item.Consume());
         }
         customer.Clear(); // clear out consumed items
         startBal = vendingMachine.Balance;
         Console.WriteLine();
         Console.WriteLine($"Total Change Due: {vendingMachine.Balance}");
         Console.WriteLine();
         Console.WriteLine(vendingMachine.Change().DueChange); // prints change in least amount of quarters, dimes and nickels
         logger.RecordTransaction("GIVE CHANGE ", startBal, startBal, vendingMachine.Balance);
         Console.WriteLine();
         Console.WriteLine("Thank You Come Again");
         Console.WriteLine();
         Delay();
         Console.Clear();
     }
     else
     {
         Console.Clear();
         Console.WriteLine();
         Console.WriteLine("There Is No Transaction To Complete");
         ErrorBuzz();
         Console.Clear();
         mainmenu.Display(vendingMachine, customer, mainmenu, logger);
     }
 }
Beispiel #2
0
        //Purchase Menu

        public void PurchaseMenu()
        {
            bool done = false;

            while (!done)
            {
                Console.WriteLine("Purchase Menu");
                Console.WriteLine("(1) Feed Money");
                Console.WriteLine("(2) Select Product");
                Console.WriteLine("(3) Finish Transaction");
                Console.WriteLine($"Current Money Provided: {vendingMachine.CurrentBalance}");
                Console.WriteLine();

                string purchaseMenuSelection = Console.ReadLine();

                //Feed Money

                if (purchaseMenuSelection == "1")
                {
                    Console.WriteLine("Please enter valid bill ($1, $2, $5, $10)");
                    decimal billAmount = decimal.Parse(Console.ReadLine());
                    Console.WriteLine();

                    if (vendingMachine.FeedMoney(billAmount) == false)
                    {
                        Console.WriteLine("Invalid amount entered, Please enter valid bill ($1, $2, $5, $10)");
                    }
                }

                //Select Product

                else if (purchaseMenuSelection == "2")
                {
                    string[] inventory = vendingMachine.InventoryListAsString();
                    foreach (string item in inventory)
                    {
                        Console.WriteLine(item);
                    }
                    Console.WriteLine("Please enter item ID: ");

                    string selection = Console.ReadLine();
                    int    answer    = vendingMachine.ValidItem(selection);

                    if (answer == 1)
                    {
                        Console.WriteLine("Invalid ID entered");
                    }
                    else if (answer == 2)
                    {
                        Console.WriteLine("Out of stock");;
                    }
                    else if (answer == 3)
                    {
                        Console.WriteLine("Not enough $");
                    }
                    else
                    {
                        vendingMachine.MakePurchase(selection);
                        Console.WriteLine(vendingMachine.PrintMessage(selection));
                        Console.WriteLine(vendingMachine.ProductPrints(selection));
                    }
                }

                //Finish Transaction; Go back to Main Menu

                else if (purchaseMenuSelection == "3")
                {
                    Dictionary <string, int> result = new Dictionary <string, int>(vendingMachine.Change());
                    foreach (KeyValuePair <string, int> kvp in result)
                    {
                        Console.WriteLine(kvp);
                    }
                    Console.WriteLine();
                    done = true;
                }
            }
        }
Beispiel #3
0
        public void RunInterface()
        {
            Prompt();
            bool done = false;

            vendingMachine.ReadItems();

            while (!done)
            {
                string input = Console.ReadLine();

                switch (input)
                {
                case "1":
                    DisplayItems();
                    break;

                case "2":
                    bool donePurchasing = false;
                    while (!donePurchasing)
                    {
                        PurchasePrompt();
                        string selection = Console.ReadLine();
                        if (selection == "1")
                        {
                            Console.WriteLine("Please enter the bill amount to feed: ");
                            int feedMoney = 0;
                            try
                            {
                                feedMoney = int.Parse(Console.ReadLine());
                                if (vendingMachine.FeedMoney(feedMoney))
                                {
                                    Console.WriteLine("Thank you.");
                                    Console.WriteLine();
                                }
                                else
                                {
                                    Console.WriteLine("Sorry, this machine can only accept US$ bills up to 10. Press enter to return to the purchase menu.");
                                    Console.ReadLine();
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error has occurred.");
                                Console.WriteLine(ex.Message);
                                Console.WriteLine("Please enter a valid amount.");
                            }
                        }
                        if (selection == "2")
                        {
                            Console.WriteLine();
                            DisplayItems();

                            Console.WriteLine("Please enter a code for the item above that you wish to purchase.");
                            string answer = Console.ReadLine();


                            if (!vendingMachine.ValidID(answer))
                            {
                                Console.WriteLine("Sorry this is not a valid code.");
                            }
                            else if (!vendingMachine.InStock(answer))      // if item is not in stock
                            {
                                Console.WriteLine("Sorry the item is out of stock.");
                            }
                            else if (!vendingMachine.EnoughMoney(answer))     // if current balance is sufficient
                            {
                                Console.WriteLine("Sorry you have insufficient funds.");
                            }
                            else
                            {
                                vendingMachine.UpdateVM(answer);
                                Console.WriteLine(vendingMachine.ItemMessage(answer));
                                Console.WriteLine();
                            }
                        }

                        if (selection == "3")
                        {
                            int[] change = vendingMachine.Change();
                            Console.WriteLine("Here is your change: " + change[0] + " Quarters & " + change[1] + " Dimes & " + change[2] + " Nickels.");

                            Console.WriteLine();
                            Console.WriteLine("Press enter to return to the main menu.");
                            Console.ReadLine();

                            donePurchasing = true;
                        }
                    }

                    break;

                case "3":
                    done = true;
                    break;
                }

                Prompt();
            }
        }