コード例 #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");
                }
            }
        }
コード例 #2
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");
                }
            }
        }
コード例 #3
0
ファイル: Menu.cs プロジェクト: joanemily/VendingMachine
        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();
            }
        }
コード例 #4
0
        public void DisplaySubMenu(VendingMachine vendingMachine, List <VendingMachineItem> customer, MainMenu mainmenu, VendingMachineLogger logger)
        {
            PurchaseMenu purchaseMenu = new PurchaseMenu();

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