Esempio n. 1
0
        /// <summary>
        /// Writes out a option menu to the console
        /// </summary>
        public void Display()
        {
            // Main Menu presented to User
            while (true)
            {
                // CLEAR console followed by display options
                Console.Clear();
                Console.WriteLine("Main Menu");
                Console.WriteLine("-------------");
                Console.WriteLine("(1) Display Vending Machine Items");
                Console.WriteLine("(2) Purchase");
                Console.WriteLine();
                Console.Write("> Pick One: ");

                // SAVE user choice
                string choice = Console.ReadLine();

                if (choice == "1")
                {
                    this.DisplayProducts();
                }
                else if (choice == "2")
                {
                    // Instantiate PurchaseMenu and pass to current vending machine
                    PurchaseMenu pm = new PurchaseMenu(this.VM, this);
                    pm.Display();
                }
                else
                {
                    Console.WriteLine("Invalid Input. Try Again");
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(@"../../../..");
            bool menum = true;

            while (menum == true)
            {
                Console.WriteLine($"\t\t\t\t\tMain Menu \n\t\t\t\t\t1) Display Items \n\t\t\t\t\t2) Purchase Menu \n\t\t\t\t\t3) Exit");
                string input = Console.ReadLine().ToLower().Trim();
                if (input.Length == 0)
                {
                    Console.Clear();
                    continue;
                }
                if (input.Length > 1)
                {
                    Console.Clear();
                    continue;
                }
                if (input == "1")
                {
                    Console.Clear();
                    Products.LoadInventory();
                    Console.WriteLine("\t\t\tPlease press [ENTER] to return to the menu");
                    Console.ReadLine();
                    Console.Clear();
                }
                if (input == "2")
                {
                    Console.Clear();
                    PurchaseMenu option = new PurchaseMenu();

                    option.PurchaseMenuUI();
                }
                if (input == "3")
                {
                    menum = false;
                    break;
                }
                //if (input == "4")
                //{
                //    Console.Clear();
                //    //TODO  Print Correct Sales Report from VendingMachine.cs, stock values are resetting.

                //    VendingMachine ex = new VendingMachine();
                //    ex.WriteOutSalesReport();
                //    Console.WriteLine("\t\t\tSales Report Printed. Please press [ENTER] to return to the menu");
                //    Console.ReadLine();
                //    Console.Clear();

                //    continue;
                //}
            }
        }
Esempio n. 3
0
        public void Run()
        {
            Console.WriteLine("====WELCOME to Vendo-Matic500====");
            Console.WriteLine("_________________________________");
            Console.WriteLine("|################################|");
            Console.WriteLine("||      ooOOOOoo      |##########|");
            Console.WriteLine("||     0000000000     |##|****|##|");
            Console.WriteLine("||     0   00   0     |##|[  ]|##|");
            Console.WriteLine("||     0oo0000oo0     |##########|");
            Console.WriteLine("||       o0oo0o       |##########|");
            Console.WriteLine("||        0000        |#|******|#|");
            Console.WriteLine("||====================|#|      |#|");
            Console.WriteLine("||                    |#|======|#|");
            Console.WriteLine("||  A1|  B2 | C3 | D4 |#| [---]|#|");
            Console.WriteLine("||====================|#|  (`) |#|");
            Console.WriteLine("||                    |#|______|#|");
            Console.WriteLine("||  A2 | B3 | C4 | D5 |##########|");
            Console.WriteLine("||====================|##########|");
            Console.WriteLine("|||||||||||||||||||||||##########|");
            Console.WriteLine("||||||||PUSH|||||||||||##########|");
            Console.WriteLine("||###############################|");
            Console.WriteLine("|--------------------------------|");

            while (true)
            {
                Console.WriteLine("Please make a choice.");
                Console.WriteLine("(1) Display Vending Machine Items");
                Console.WriteLine("(2) Purchase");
                Console.WriteLine("(Q) Quit");
                string choice = Console.ReadLine();
                Console.WriteLine();

                if (choice == "1")
                {
                    Console.Clear();
                    vm.DisplayStock();
                }
                else if (choice == "2")
                {
                    Console.Clear();
                    PurchaseMenu pm = new PurchaseMenu(vm, log);
                    pm.Run();
                }
                else if (choice == "Q" || choice == "q")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid input.");
                    Console.ReadLine();
                }
            }
        }
Esempio n. 4
0
        public void Run(VendingMachine vendingMachine)
        {
            while (true)
            {
                Console.WriteLine("1. Display Vending Machine Items.");
                Console.WriteLine("2. Purchase Item(s)");
                Console.WriteLine("Q  Quit");
                Console.Write("Choice: ");
                string choice = Console.ReadLine();
                Console.WriteLine();

                if (choice == "1")
                {
                    // Display read in inventory
                    Console.Clear();
                    vendingMachine.DisplayItems();
                }
                else if (choice == "2")
                {
                    // instantiate purchase menu and pass vendingMachine object
                    PurchaseMenu purchaseMenu = new PurchaseMenu();
                    purchaseMenu.Run(vendingMachine);
                }
                else if (choice.ToLower() == "q")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Not a valid choice, please try again.");
                    Console.WriteLine();
                }
            }

            //computing total sale resport for life cycle of instantiated vending machine
            vendingMachine.TotalSalesReport();
        }
Esempio n. 5
0
        /// <summary>
        /// Displays the main menu.
        /// </summary>
        public void Display()
        {
            PrintHeader();

            while (true)
            {
                DisplayMenuOptions();

                Console.Write("What option do you want to select? ");
                string input = Console.ReadLine().ToUpper();

                // Displays all items and their price to the user.
                if (input == "1")
                {
                    ItemDisplay items = new ItemDisplay(this.Vm);
                    items.Display();
                }
                // Takes the user to the purchase menu.
                else if (input == "2")
                {
                    PurchaseMenu purchase = new PurchaseMenu(this.Vm);
                    purchase.Display();
                }
                // Exits the program.
                else if (input == "Q" || input == "q")
                {
                    Console.WriteLine("Quitting");
                    break;
                }
                // Asks the user to try again if they entered an invalid input.
                else
                {
                    Console.WriteLine("Please try again");
                }
            }
        }
Esempio n. 6
0
        public void Display()
        {
            Console.Clear();
            //Display menu options
            Console.WriteLine(@"
    _______    ______     ___    __                          __
   /__  __//  / ____//    | ||  / //________________________/ //__(_))___________________ 
     / //    / __//       | || / // /  _\\  / ___ \\  /  __  //  / //  / ___ \\  / ___ `//
    / //    / //___       | ||/ // /  __// / // / // / //_/ //  / //  / // / // / //_/ // 
   /_//    /_____//       |____//  \___// /_// /_//  \___,_//  /_//  /_// /_//  \__,  //  
                                                                               /_____//                            
                    *************************************************
                    **  Please choose from the following options:  **
                    **      1. Display Vending Machine Items       **
                    **      2. Purchase Menu                       **
                    **      3. Exit                                **
                    **                                             **
                    *************************************************");

            //Get user input
            int selection;

            Console.WriteLine();
            Console.Write("Please enter your selection: ");
            bool isValid = int.TryParse(Console.ReadLine(), out selection);

            //Validate the user input
            while (!isValid || selection < 1 || selection > 4)
            {
                Console.WriteLine("You did not enter a valid choice please enter the number corresponding to your selection");
                isValid = int.TryParse(Console.ReadLine(), out selection);
            }

            // Choose which methods to call based on user selection
            if (selection == 1)
            {
                // Clear the console and display Menu Items
                Console.Clear();
                DisplayItems.Display(vm);
                Console.WriteLine();
                Console.WriteLine("Press Enter to return to main menu");
                Console.ReadLine();
                Display();
            }
            else if (selection == 2)
            {
                // Display Purchase Menu by creating a new purchase menu object and passing the vending machine reference to its contructor
                PurchaseMenu pm = new PurchaseMenu(vm);
                pm.Display();
            }
            else if (selection == 3)
            {
                // Exit Program
                return;
            }
            else if (selection == 4)
            {
                // Generate a sales report and print it to file.
                vm.PrintSalesReport();

                //Inform the user that a report was generated and return to main menu
                Console.WriteLine();
                Console.WriteLine("Sales report generated, check the SalesReport folder to view the report.");
                Console.WriteLine("Press enter to continue...");
                Console.ReadLine();
                Display();
            }
        }
        public void Display(VendingMachine vendingMachine, List <VendingMachineItem> customer, MainMenu mainmenu, PurchaseMenu purchaseMenu, VendingMachineLogger logger)
        {
            try
            {
                // variables for keeping track of various user inputs and interaction
                string         input;
                ConsoleKeyInfo key;
                int            addedMoney      = 0;
                decimal        startingBalance = 0.00m;
                decimal        moneyFed        = 0.00m;
                decimal        price           = 0.00m;
                bool           stayInSubMenu   = true;
                string         item;

                while (stayInSubMenu)
                {
                    MenuMusic();
                    Console.WriteLine();
                    Console.WriteLine("Purchase Menu".PadLeft(18));
                    Console.WriteLine("  ________________________");
                    Console.WriteLine("1] >> Insert Money");
                    Console.WriteLine("2] >> Purchase Items");
                    Console.WriteLine("3] >> Return To Main Menu");
                    Console.WriteLine();
                    Console.WriteLine($"Current Balance: ${vendingMachine.Balance}");
                    Console.WriteLine();
                    Console.Write("Select Your Option: ");

                    // prompt user to select an option

                    key = Console.ReadKey();
                    ButtonClick();

                    if (key.KeyChar == '1')
                    {
                        Console.Clear();
                        Console.Write("Insert $1 Or $5 Bills: $ ");

                        // prompt user to insert bills of various denominations

                        key = Console.ReadKey();
                        int.TryParse(key.KeyChar.ToString(), out addedMoney);// storing users input to a variable to pass in to the purchasing methods
                        ButtonClick();

                        if (addedMoney <= 5 && addedMoney > 0)
                        {
                            stayInSubMenu = false;
                            Console.WriteLine();

                            // add the money to the balance and also pass the various information in to the logger
                            // TO DO - turn this in to a method to clean up clutter in the menu classes

                            startingBalance = vendingMachine.Balance;
                            moneyFed        = addedMoney + 0.00m;
                            vendingMachine.FeedMoney(addedMoney);
                            logger.RecordTransaction("FEED MONEY : ", startingBalance, moneyFed, vendingMachine.Balance);
                            Console.Clear();

                            // return to purchase menu

                            DisplaySubMenu(vendingMachine, customer, mainmenu, logger);
                            break;
                        }
                        else
                        {
                            // error message to limit accepted bill denominations ,
                            //  and make it a pain in the ass to add unrealistic amounts of money in to the machine
                            Console.WriteLine();
                            Console.WriteLine("Machine Only Accepts $1 And $5 Bills ");
                            Console.WriteLine();
                        }
                    }
                    else if (key.KeyChar == '2')
                    {
                        Console.Clear();

                        // display machine inventory
                        DisplayMachineItems(vendingMachine);
                        Console.WriteLine();
                        Console.Write("Which item would you like to purchase(press Q to leave)? ");

                        // prompt user to select an inventory item

                        input = Console.ReadLine();
                        ButtonClick();

                        if (input.ToLower() == "q")
                        {
                            // lets user quit menu without making a selection
                            Console.Clear();
                            Console.WriteLine("Returning To Purchase Menu");
                        }
                        else
                        {
                            // if balance is enough AND item is in stock, this will perform the necessary purchase functions
                            // and dispense items from the vending machine to the customers bin ( list )
                            Console.Clear();
                            price           = vendingMachine.GetItemAtSlot(input).Price;
                            startingBalance = vendingMachine.Balance;
                            item            = vendingMachine.GetItemAtSlot(input).ItemName;
                            MakePurchase(input, item, startingBalance, price, vendingMachine.Balance, vendingMachine, customer, logger, mainmenu);
                        }
                    }
                    else if (key.KeyChar == '3')
                    {
                        // return to main menu
                        stayInSubMenu = false;
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("Returning To Main Menu");
                        mainmenu.Display(vendingMachine, customer, mainmenu, logger);
                        Console.Clear();
                    }
                    else
                    {
                        // prevents user from entering invalid inputs
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("Please Select A Valid Menu Option");
                        ErrorBuzz();
                        Console.Clear();
                    }
                }
            }
            catch (KeyNotFoundException)
            {
                // prevents user from selecting an invalid product code
                Console.WriteLine();
                Console.WriteLine("Invalid Product Code");
                ErrorBuzz();
                DisplaySubMenu(vendingMachine, customer, mainmenu, logger);
            }
            catch (IndexOutOfRangeException)
            {
                // prevents the unlikely case of an index out of bounds error being thrown
                Console.Clear();
                Console.WriteLine();
                Console.WriteLine("Please Make Your Selection Again");
                ErrorBuzz();
                DisplaySubMenu(vendingMachine, customer, mainmenu, logger);
            }
            catch (NullReferenceException)
            {
                // prevents the unlikely case of a nullref being thrown
                Console.WriteLine();
                Console.WriteLine("Please Select Another Product");
                ErrorBuzz();
                DisplaySubMenu(vendingMachine, customer, mainmenu, logger);
            }
            catch (FormatException)
            {
                // prevents invalid input error in the feed money function
                Console.Clear();
                Console.WriteLine();
                Console.WriteLine("Please Enter $1 Or $5 Dollar Bills");
                ErrorBuzz();
                DisplaySubMenu(vendingMachine, customer, mainmenu, logger);
            }
        }
        public void DisplaySubMenu(VendingMachine vendingMachine, List <VendingMachineItem> customer, MainMenu mainmenu, VendingMachineLogger logger)
        {
            PurchaseMenu purchaseMenu = new PurchaseMenu();

            purchaseMenu.Display(vendingMachine, customer, mainmenu, purchaseMenu, logger);
        }