Пример #1
0
        public void Run()
        {
            vm.CreateUpdateVendingMachineInventory();
            bool exit = false;

            while (!exit) //run this is an infinite loop. You'll need a 'finished' option and then you'll break after that option is selected
            {
                string selection = (string)ui.PromptForSelection(MAIN_MENU_OPTIONS);
                if (selection == MAIN_MENU_OPTION_DISPLAY_ITEMS)//presses 1 to display the items
                {
                    vm.DisplayItems();
                }
                else if (selection == MAIN_MENU_OPTION_PURCHASE)//presses 2 to purchase
                {
                    PurchaseMenu();
                }
                else if (selection == MAIN_MENU_OPTION_EXIT)//presses 3 to Exit
                {
                    exit = true;
                }
                else if (selection == MAIN_MENU_OPTION_SALES_REPORT)//presses 4 to purchase
                {
                    vm.WriteToTotalSalesReport();
                }
            }
        }
Пример #2
0
 public void Run()
 {
     Console.WriteLine("Vendo - Matic 600");
     Console.WriteLine("by Umbrella Corp.");
     vm.PopulateVendingMachine();
     while (true)
     {
         string selection = (string)ui.PromptForSelection(MAIN_MENU_OPTIONS);
         if (selection == MAIN_MENU_OPTION_DISPLAY_ITEMS)
         {
             vm.DisplayItems();
         }
         else if (selection == MAIN_MENU_OPTION_PURCHASE)
         {
             vm.PurchaseItemsSubmenu();
         }
         else if (selection == MAIN_MENU_OPTION_EXIT)
         {
             break;
         }
         else if (selection == SECRET_MENU_OPTION_SALES_REPORT)
         {
             vm.GenerateSalesReport();
             break;
         }
     }
 }
        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
        //test would create and infinite loop because currentBalance is set through a void method on program.cs
        public decimal UserInput2(decimal currentBalance) //Purchase item
        {
            vendoMatic.DisplayItems();
            Console.WriteLine("Please enter the location code for your item.");
            string enteredItemID = Console.ReadLine().ToUpper();
            Item   selectedItem  = new Item(enteredItemID);

            //check if entered Item ID exists
            if (!selectedItem.ItemExists(enteredItemID))
            {
                Console.WriteLine("You have entered an invalid item code");
            }
            else if (selectedItem.ItemExists(enteredItemID) && vendoMatic.IsOutOfStock(enteredItemID))
            {
                Console.WriteLine("The item you selected is SOLD OUT");
            }
            else if (currentBalance >= selectedItem.ItemPrice) //Purchse Item succesful
            {
                vendoMatic.DispenseItem(enteredItemID, currentBalance);
                currentBalance = currentBalance - selectedItem.ItemPrice;
                //salesReport.UpdateSalesReport(enteredItemID);
                try
                {
                    using (StreamWriter sw = new StreamWriter(outputFile, true))
                    {
                        sw.WriteLine(now.ToString() + $" {selectedItem.ItemName} {selectedItem.ItemID} ${currentBalance + selectedItem.ItemPrice} ${currentBalance}");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("There was an error");
                    Console.WriteLine(e.Message);
                    //return to PurchaseItems menu and rerun
                }
            }
            else if (currentBalance < selectedItem.ItemPrice)
            {
                Console.WriteLine("You do not have enough money to make that purchase. Please input money.");
            }

            return(currentBalance);
        }
Пример #6
0
        static void Main(string[] args)
        {
            try
            {
                bool isComplete = false;

                while (!isComplete)
                {
                    string choice         = "";
                    bool   exitToMainMenu = false;
                    ReadInInputFile.InputInventory();
                    Console.WriteLine("Welcome to the Vend-Matic 500!");
                    Console.WriteLine();
                    Console.WriteLine("Please see our menu options below.");
                    Console.WriteLine("(1) Display items");
                    Console.WriteLine("(2) Purchase");
                    choice = Console.ReadLine();
                    if (choice == "1")
                    {
                        VendingMachine.DisplayItems();
                        Console.WriteLine("Please press(2) to make a purchase: ");
                        choice = Console.ReadLine();
                    }
                    if (choice == "2")
                    {
                        decimal fedMoney = 0;
                        do
                        {
                            Console.WriteLine("Purchase Menu");
                            Console.WriteLine("(1) Feed Money");
                            Console.WriteLine("(2) Select Product");
                            Console.WriteLine("(3) Finish Transaction");
                            Console.WriteLine("Current Money Provided: $" + fedMoney);
                            string selection = Console.ReadLine();
                            if (selection == "1")
                            {
                                Console.WriteLine("Please feed money in whole dollar amounts($1, $5, $10, or $20)");
                                Console.WriteLine("How much money do you want to feed?");
                                string fedMoneyString = Console.ReadLine();
                                if (fedMoneyString == "1" || fedMoneyString == "5" || fedMoneyString == "10" || fedMoneyString == "20")
                                {
                                    fedMoney += VendingMachine.FeedMoney(fedMoneyString);
                                }
                                else
                                {
                                    Console.WriteLine("Incorrect denomination. The money fed must be in whole dollar amounts(ex. $1, $5, etc)");
                                    Console.WriteLine();
                                }
                            }
                            if (selection == "2")
                            {
                                VendingMachine.DisplayItems();
                                Console.WriteLine("Please type your selection(ex. A1)");
                                string selectedProduct = Console.ReadLine().ToUpper();
                                if (VendingMachine.vendMachine.ContainsKey(selectedProduct))
                                {
                                    fedMoney = VendingMachine.PurchaseItem(selectedProduct, fedMoney);
                                }
                                else
                                {
                                    Console.WriteLine("Incorrect entry. Item does not exist!");
                                    Console.WriteLine();
                                }
                            }
                            if (selection == "3")
                            {
                                VendingMachine.DispenseChange(fedMoney);
                                Console.WriteLine("Are sure you want to finish you transaction? ");
                                string exitQuestion = Console.ReadLine().ToUpper();
                                if (exitQuestion == "N")
                                {
                                    exitToMainMenu = false;
                                }
                                if (exitQuestion == "Y")
                                {
                                    exitToMainMenu = true;
                                }

                                fedMoney = 0;
                            }
                        }while (!exitToMainMenu);
                    }


                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            // Will Track Total Profit of Vending Machine for Sales Report
            decimal totalProfit = 0;

            decimal balance = 0;

            VendingMachine vendingMachine = new VendingMachine();

            while (true)
            {
                Console.WriteLine("\n**Welcome to the Vend-O-Matic 4000**\n\nSelect Option Below\n-------------------");
                Console.WriteLine("(1) View Inventory \n(2) Select Product \n(3) Quit\n");
                Console.Write($"> Current Balance: ${balance} \n\n>>:");
                string menu = Console.ReadLine();
                Console.WriteLine("");

                if (menu == "1")
                {
                    vendingMachine.DisplayItems();
                }
                else if (menu == "2")
                {
                    bool valid = false;

                    do
                    {
                        Console.Write(">> Please enter the location of the product you'd like to puchase: ");

                        string input = Console.ReadLine().ToUpper();

                        valid = false;

                        if (vendingMachine.inventory.ContainsKey(input))
                        {
                            Product product = vendingMachine.inventory[input];

                            if (product.Quantity > 0)
                            {
                                Console.Write($"\n> Price of item selected : ${product.Price} \n\n> {product.Quantity} Remaining\n");

                                bool run = true;

                                while (run)
                                {
                                    Console.Write($"\n> Current Balance is ${balance}\n\n>> Please Enter a Whole Dollar Amount(1, 2, 5, 10), (d) to dispence or (s) to start over\n\n>>: ");
                                    string input2 = Console.ReadLine();

                                    if (input2 == "1" || input2 == "2" || input2 == "5" || input2 == "10")
                                    {
                                        int amount = int.Parse(input2);
                                        balance += (decimal)amount;

                                        Console.WriteLine($"> ${input2} inserted.");

                                        using (StreamWriter sw = new StreamWriter("log.txt", true))
                                        {
                                            sw.WriteLine($"{DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt")} FEED MONEY: ${amount}     ${balance}");
                                        }
                                    }
                                    else if (input2 == "D" || input2 == "d")
                                    {
                                        if (balance >= product.Price)
                                        {
                                            run = false;
                                            vendingMachine.DispenseProduct(input);
                                            using (StreamWriter sw = new StreamWriter("log.txt", true))
                                            {
                                                sw.WriteLine($"{DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt")} {product.Name} {product.Location} ${balance}     ${balance - product.Price}");
                                            };
                                            balance     -= product.Price;
                                            totalProfit += product.Price;
                                        }
                                        else
                                        {
                                            Console.WriteLine("> Insufficient Funds, please add more money.");
                                        }
                                    }
                                    else if (input2 == "S" || input2 == "s")
                                    {
                                        Console.WriteLine("");
                                        break;
                                    }
                                    else
                                    {
                                        Console.WriteLine("> Invalid Entry. Please enter valid input.");
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("\n>>Sorry that item is SOLD OUT<<\n");
                            }
                        }
                        else
                        {
                            Console.WriteLine("\n> Invalid Entry. Please enter valid input.\n");
                            valid = true;
                        }
                    } while (valid);
                }
                else if (menu == "3")
                {
                    Console.WriteLine("> Thank You for using Vend-O-Matic 4000!");
                    Console.WriteLine($"> Your remaining balance is: ${balance}");

                    using (StreamWriter sw = new StreamWriter("log.txt", true))
                    {
                        sw.WriteLine($"{DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt")} GIVE CHANGE: ${balance}     $0.00");
                    };
                    int numQuarter = 0;
                    int numDime    = 0;
                    int numNickel  = 0;

                    while (balance > 0)
                    {
                        if (balance >= 0.25M)
                        {
                            numQuarter++;
                            balance -= 0.25M;
                        }
                        else if (balance >= 0.10M)
                        {
                            numDime++;
                            balance -= 0.10M;
                        }
                        else if (balance >= 0.50M)
                        {
                            numNickel++;
                            balance -= 0.05M;
                        }
                    }

                    Console.WriteLine($"> Here is your change: {numQuarter} Quarter(s), {numDime} Dime(s), {numNickel} Nickel(s).\n");
                    Console.WriteLine("\n------------------------------------------------------------------------------\n");
                }
                else if (menu == "4")
                {
                    foreach (KeyValuePair <string, Product> kvp in vendingMachine.inventory)
                    {
                        Console.WriteLine($"{kvp.Value.Name} | {kvp.Value.Sold}");
                    }

                    Console.WriteLine($"\n\n**TOTAL SALES** ${totalProfit}\n");
                }
                else
                {
                    Console.WriteLine("\n> Invalid Entry. Please enter valid input.\n");
                }
            }
        }