コード例 #1
0
        /// <summary>
        /// Run an infinite loop until "break."
        /// </summary>
        public void Run()
        {
            while (true)
            {
                Console.WriteLine("Welcome to Vendo-Matic 500!");
                Console.WriteLine("Please make a choice.");
                Console.WriteLine("1. Display Vending Machine items.");
                Console.WriteLine("2. Purchase.");
                Console.WriteLine("3. Quit.");
                Console.WriteLine("> Please Pick One: ");
                string choice = Console.ReadLine();

                if (choice == "1")
                {
                    DisplayMenu displayMenu = new DisplayMenu();
                    displayMenu.Run(vm.inventory);
                }
                else if (choice == "2")
                {
                    PurchaseMenu purchaseMenu = new PurchaseMenu();
                    purchaseMenu.Run(vm);
                }
                else if (choice == "3")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid option.");
                    Console.ReadLine();
                }
            }
        }
コード例 #2
0
ファイル: MainMenu.cs プロジェクト: dwperez74/vend
        private MenuOptionResult PurchaseMenu()
        {
            PurchaseMenu purchaseMenu = new PurchaseMenu(vendingMachine);

            purchaseMenu.Show();
            return(MenuOptionResult.WaitAfterMenuSelection);
        }
コード例 #3
0
        public void Run()
        {
            VendingMachine vm = new VendingMachine();


            while (true)
            {
                Console.Write(@"
                Welcome, Hungry One. Please select an option.

                (1) Display Vending Item Selection
                (2) Purchase Item
                (3) Exit Vendomatic 800
                
                Enter your option here: ");


                string input = Console.ReadLine().Trim();
                Console.Clear();

                if (input == "1")
                {
                    Console.Clear();
                    Console.WriteLine("Display vending machine items");
                    Console.WriteLine();
                    vm.DisplayItems();
                    Console.WriteLine();
                    Console.WriteLine("Press enter to continue");
                    Console.ReadLine();
                    Console.Clear();
                }

                else if (input == "2")
                {
                    // Simplifying to call a new purchase menu using this info so it sends the user to that menu from here
                    Console.Clear();
                    PurchaseMenu pm = new PurchaseMenu(vm);
                    pm.Run();
                }

                else if (input == "3")
                {
                    Console.WriteLine("Goodbye!");
                    break;
                }

                else if (input == "4")
                {
                    vm.PrintSalesReport();
                }

                else
                {
                    Console.WriteLine($"{input} is invalid. Please enter 1, 2, or 3. Thank you!");
                }
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Vendo-Matic 800!");
            decimal        currentBalance = 0.00M;
            VendingMachine vendoMatic     = new VendingMachine();
            SalesReport    salesReport    = new SalesReport();
            MainMenu       main           = new MainMenu();
            PurchaseMenu   purchase       = new PurchaseMenu();
            Money          money          = new Money(currentBalance);


            bool showMainMenu = true;

            while (showMainMenu)
            {
                main.DisplayMainMenu();
                string userInputMain = Console.ReadLine();
                switch (userInputMain)
                {
                case "1":
                    vendoMatic.DisplayItems();
                    main.menuSpacer();
                    showMainMenu = true;
                    break;

                case "2":
                    purchase.PurchaseItemsMenu(money.CurrentBalance);
                    showMainMenu = true;
                    break;

                //case "4":
                //    Console.WriteLine("Sales Report");
                //    main.menuSpacer();
                //    //PrintSalesReport();
                //    showMainMenu = true;
                //    break;
                case "3":
                    //salesReport.LogSalesReport();
                    showMainMenu = false;
                    break;

                default:
                    Console.WriteLine(main.InvalidOption());
                    showMainMenu = true;
                    break;
                }
            }

            main.menuSpacer();
            Console.WriteLine("Thank you! Please come again!");
        }
コード例 #5
0
        public void DisplayMainMenu()

        {
            bool keepGoing = true;

            while (keepGoing)
            {
                Console.Clear();
                DisplayLogo();
                Console.WriteLine("1) Display Vending Machine Items");
                Console.WriteLine("2) Purchase"); // go to PurchaseMenu
                Console.WriteLine("3) Exit");
                Console.Write("Please Enter Selection: ");
                string input = Console.ReadLine();

                switch (input)
                {
                case "1":
                    Dictionary <string, VendingMachineItem> items = VM.Inventory;
                    DisplayItems(items);
                    Console.WriteLine("\nPress Enter to Return to Main Menu Selection.");
                    break;

                case "2":
                    PurchaseMenu pm = new PurchaseMenu(VM);
                    pm.DisplayPurchaseMenu();
                    break;

                case "3":
                    keepGoing = false;
                    continue;

                case "4":
                    SalesReporter.Report(VM.Inventory);
                    Console.WriteLine($"A sales report has been generated");
                    break;

                default:
                    Console.WriteLine("Invalid Menu Option. Please try again.");
                    continue;
                }
                Console.ReadLine();
            }
        }
コード例 #6
0
ファイル: MainMenu.cs プロジェクト: pearcer15/MyProjects
        /// <summary>
        /// RUns the menu
        /// </summary>
        /// <param name="machine">machine menu is running on</param>
        public virtual void Run(VendingMachine machine)
        {
            this.vM500 = machine;

            while (true)
            {
                string choice = string.Empty;
                while (choice != "1" && choice != "2" && choice != "Q")
                {
                    Console.Clear();
                    Console.WriteLine("Welcome to the Vendo-Matic 500!");
                    Console.WriteLine();
                    Console.WriteLine("1. Display Vending Machine Items");
                    Console.WriteLine("2. Purchase");
                    Console.WriteLine("Q. Quit");
                    Console.Write("Please make a selection: ");
                    choice = Console.ReadLine().ToUpper();
                }

                switch (choice)
                {
                case "1":
                    this.DisplayInventory(this.vM500);
                    Console.ReadLine();
                    break;

                case "2":
                    PurchaseMenu pm = new PurchaseMenu();
                    pm.Run(this.vM500);
                    break;

                case "Q":
                    this.SalesReport();
                    return;

                default:
                    break;
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Runs main menu for our vending machine. Inputs are location of files for program.
        /// </summary>
        /// <param name="inventoryList"></param>
        /// <param name="logs"></param>
        /// <param name="salesReport"></param>
        public static void MainMenu(VendingMachine vendingMachine)
        {
            bool isExit = false;

            while (!isExit)
            {
                Console.Clear();
                Console.WriteLine("Welcome to Vendo-Matic 600!");
                Console.WriteLine("by Umbrella Corp.");
                Console.WriteLine();

                Console.WriteLine("Menu options:");
                Console.WriteLine($"{DISPLAY_KEY.ToString().Substring(1)}. Display items.");
                Console.WriteLine($"{PURCHASE_KEY.ToString().Substring(1)}. Purchase items.");
                Console.WriteLine($"{EXIT_KEY.ToString().Substring(1)}. Exit.");

                var menuSelection = Console.ReadKey().Key;

                if (menuSelection == DISPLAY_KEY)
                {
                    DisplayMenu.DisplayItemsMenu(vendingMachine);
                }
                else if (menuSelection == PURCHASE_KEY)
                {
                    PurchaseMenu.PurchaseItemsMenu(vendingMachine);
                }
                else if (menuSelection == EXIT_KEY)
                {
                    isExit = true;
                }
                else if (menuSelection == REPORT_KEY)
                {
                    vendingMachine.MakeSalesReport();

                    DisplayMessage("A new Sales Report has been generated.");
                }
            }
        }
コード例 #8
0
        public void Display()
        {
            while (true)
            {
                PrintHeader();

                Console.WriteLine();
                Console.WriteLine("Main Menu");
                Console.WriteLine("1] >> Display Vending Machine Items");
                Console.WriteLine("2] >> Make Purchase");
                Console.WriteLine("Q] >> Quit");

                Console.Write("Please make a selection: ");
                string input = Console.ReadLine();

                if (input == "1")
                {
                    Console.WriteLine("Displaying Vend-O-Matic 500 Items...");
                    vm.PrintAllItemsInfo();
                }
                else if (input == "2")
                {
                    PurchaseMenu pm = new PurchaseMenu(vm);
                    pm.Display();
                }
                else if (input == "Q")
                {
                    Console.WriteLine("Quitting");
                    break;
                }
                else
                {
                    Console.WriteLine("Please try again");
                }
            }
        }
コード例 #9
0
        static void Main(string[] args)
        {
            //here is where the program actually runs and will log the transaction choices
            string logDirectory     = Path.GetFullPath(Environment.CurrentDirectory + @"\..\..\..\..");
            string auditLog         = "Log.txt";
            string fullLogDirectory = Path.Combine(logDirectory, auditLog);
            Logger audit            = new Logger();

            Console.WriteLine("Welcome to the Interdimensional Vending Machine!");
            Console.WriteLine();
            //this next line is creating an instance of CashRegister so that we can set the stored money in the machine at the beginning to zero & manipulate it
            CashRegister             storedMoney    = new CashRegister(0M);
            VendingMachineDictionary vendingMachine = new VendingMachineDictionary();
            MainMenu firstDisplay         = new MainMenu();
            string   userMainMenuResponse = "";

            //if the user did not choose to exit, then we're doing something!
            while (userMainMenuResponse != "3")
            {
                firstDisplay.StartingScreen();
                userMainMenuResponse = Console.ReadLine();
                Console.WriteLine();

                //they picked list so this shows them the available items, as well as their prices, stock amount and location
                if (userMainMenuResponse == "1")
                {
                    Console.Clear();
                    foreach (string key in vendingMachine.VendingItemList.Keys)
                    {
                        //if we don't have any we can't sell it, let them know it's sold out
                        if (vendingMachine.VendingItemList[key].ItemStock == 0)
                        {
                            Console.WriteLine($"{key} {vendingMachine.VendingItemList[key].ItemName} " +
                                              $"{vendingMachine.VendingItemList[key].ItemPrice} " +
                                              $"SOLD OUT!");
                        }
                        //if we have it let's sell it, let them know the name, price, and how much of it is left
                        else
                        {
                            Console.WriteLine($"{key} {vendingMachine.VendingItemList[key].ItemName} " +
                                              $"{vendingMachine.VendingItemList[key].ItemPrice} " +
                                              $"{vendingMachine.VendingItemList[key].ItemStock}");
                        }
                    }
                }
                //this means they are choosing to purchase something
                else if (userMainMenuResponse == "2")
                {
                    Console.Clear();
                    //the line above this has cleared away the previous menu and selections; makes it cleaner

                    //the line below this is storing whether the user is adding money, choosing an item or done
                    string userPurchaseResponse = "";
                    while (userPurchaseResponse != "3")
                    {
                        PurchaseMenu purchaseMenu = new PurchaseMenu();
                        purchaseMenu.PurchaseMenuScreen();
                        Console.WriteLine();
                        Console.WriteLine($"Current Money Provided: ${storedMoney.MoneyInputed}");
                        userPurchaseResponse = Console.ReadLine();
                        //user wants to input money
                        if (userPurchaseResponse == "1")
                        {
                            Console.Clear();
                            Console.WriteLine($"Please enter the value of the bill you've paid with (Valid values: 1, 2, 5, or 10).");
                            string  usersInsertedMoney   = Console.ReadLine();
                            decimal moneyAddedToRegister = 0;
                            //comparing the user's input amount to a valid option
                            if (usersInsertedMoney == "1")
                            {
                                moneyAddedToRegister = 1;
                            }
                            else if (usersInsertedMoney == "2")
                            {
                                moneyAddedToRegister = 2;
                            }
                            else if (usersInsertedMoney == "5")
                            {
                                moneyAddedToRegister = 5;
                            }
                            else if (usersInsertedMoney == "10")
                            {
                                moneyAddedToRegister = 10;
                            }
                            //if the amount the user inputed is not valid it will kick out this error message
                            else
                            {
                                Console.WriteLine("Sorry but the amount you used isn't valid for our machine, or you used a \"$\"!");
                                Console.WriteLine();
                            }
                            // this is the key reason for the moneyAddedToRegister variable, it allows us to log the money added to the text file along with whats already stored in the register
                            if (moneyAddedToRegister > 0)
                            {
                                storedMoney.MoneyInputed += moneyAddedToRegister;
                                audit.LogFeed(storedMoney.MoneyInputed, moneyAddedToRegister);
                            }
                        }
                        //user wants to select an item to buy
                        else if (userPurchaseResponse == "2")
                        {
                            try
                            {
                                Console.Clear();
                                Console.WriteLine("Please select an item below using the slot number (A1, A2, A3, etc.)");
                                Console.WriteLine();
                                string userItemSlotLocation;
                                foreach (string key in vendingMachine.VendingItemList.Keys)
                                {
                                    //will not let user purchase something that is out of stock, spits out error message
                                    if (vendingMachine.VendingItemList[key].ItemStock == 0)
                                    {
                                        Console.WriteLine($"{key} {vendingMachine.VendingItemList[key].ItemName} " +
                                                          $"{vendingMachine.VendingItemList[key].ItemPrice} " +
                                                          $"SOLD OUT!");
                                    }
                                    else
                                    {
                                        Console.WriteLine($"{key} {vendingMachine.VendingItemList[key].ItemName} " +
                                                          $"{vendingMachine.VendingItemList[key].ItemPrice} " +
                                                          $"{vendingMachine.VendingItemList[key].ItemStock}");
                                    }
                                }
                                //records what the user selected
                                userItemSlotLocation = Console.ReadLine();
                                Console.Clear();
                                audit.LogItem(vendingMachine.VendingItemList[userItemSlotLocation.ToUpper()].ItemName, storedMoney.MoneyInputed,
                                              vendingMachine.VendingItemList[userItemSlotLocation.ToUpper()].ItemPrice, userItemSlotLocation.ToUpper());
                                // checking if the user selection is in the dictionary
                                if (!vendingMachine.VendingItemList.ContainsKey(userItemSlotLocation.ToUpper()))
                                {
                                    Console.WriteLine("Sorry, that is an invalid slot location. Try again!");
                                }
                                else if (vendingMachine.VendingItemList[userItemSlotLocation.ToUpper()].ItemStock == 0)
                                {
                                    Console.WriteLine("Sorry, that item is sold out. Please try again.");
                                }
                                else if (vendingMachine.VendingItemList[userItemSlotLocation.ToUpper()].ItemPrice > storedMoney.MoneyInputed)
                                {
                                    Console.WriteLine("CHEAPSKATE.......I NEED MORE MONEY THAN THAT!");
                                }
                                else if (vendingMachine.VendingItemList[userItemSlotLocation.ToUpper()].ItemStock > 0)
                                {
                                    // takes the money in the register and subtracts the item price from it
                                    storedMoney.MoneyInputed -= vendingMachine.VendingItemList[userItemSlotLocation.ToUpper()].ItemPrice;
                                    // lowers the stock of the item by 1
                                    vendingMachine.VendingItemList[userItemSlotLocation.ToUpper()].ItemStock--;
                                    Console.WriteLine($"{vendingMachine.VendingItemList[userItemSlotLocation.ToUpper()].ItemName} " +
                                                      $"{vendingMachine.VendingItemList[userItemSlotLocation.ToUpper()].ItemPrice} {storedMoney.MoneyInputed}");
                                    Console.WriteLine(vendingMachine.VendingItemList[userItemSlotLocation.ToUpper()].MakeSound());
                                }
                            }
                            catch
                            {
                                Console.WriteLine("Sorry, that is an invalid entry!");
                                Console.WriteLine();
                            }
                            Console.WriteLine();
                        }
                        else if (userPurchaseResponse == "3")
                        {
                            //ends the loop
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Invalid Menu option! Try again.");
                            Console.WriteLine();
                        }
                    }
                    Console.WriteLine();
                    audit.LogChange(storedMoney.MoneyInputed);
                    //giving change
                    Console.WriteLine(storedMoney.Change(storedMoney.MoneyInputed));
                    //resets money in register to 0
                    storedMoney.MoneyInputed = 0M;
                    Console.WriteLine();
                }
                else if (userMainMenuResponse == "3")
                {
                    Environment.Exit(0);
                }
                else
                {
                    Console.WriteLine("Invalid Menu option! Try again.");
                    Console.WriteLine();
                }
            }
        }