Exemplo n.º 1
0
        public void Display()
        {
            PrintHeader();

            VendingMachine vm = new VendingMachine();

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("(1) Display Vending Machine Items");
                Console.WriteLine("(2) Purchase");
                Console.WriteLine("(Q) Quit");
                Console.WriteLine("What option do you want to select?");

                string input = Console.ReadLine();
                if (input == "1")
                {
                    Console.WriteLine("Slot ID".PadRight(11) + "Product".PadRight(21) + "Price".PadRight(11) + "Quantity".PadRight(10));
                    Console.WriteLine();
                    foreach (string slot in vm.Slots) // Loop through items in inventory
                    {
                        VendingItem product = vm.GetItemAtSlot(slot);
                        if (product == null)
                        {
                            Console.WriteLine("Sold out!");
                        }
                        else
                        {
                            string item  = product.Name.PadRight(20) + " ";
                            string price = product.Cost.ToString().PadRight(10) + " ";

                            Console.WriteLine(slot.PadRight(10) + " " + item + price + "in stock"); // Displays vending items with quantity remaining
                        }
                    }
                }
                else if (input == "2")
                {
                    SubMenu submenu = new SubMenu(vm);
                    submenu.Display();
                }
                else if (input == "Q" || input == "q")
                {
                    return;
                }
                else
                {
                    Console.WriteLine("Please try again.");
                }
            }
        }
        public void Display()
        {
            Reader r = new Reader();
            Dictionary <string, List <Item> > inventory = r.ReadVendingMachineItems();

            VendingMachine machine = new VendingMachine(inventory);

            for (int i = 0; i < 3; i++)
            {
                Console.Clear();
                System.Threading.Thread.Sleep(750);
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("                         Welcome to: ");
                System.Threading.Thread.Sleep(750);
            }

            Console.Clear();
            Console.WriteLine(@"__      __            _               __  __       _   _        _____  ___   ___");
            Console.WriteLine(@"\ \    / /           | |             |  \/  |     | | (_)      | ____|/ _ \ / _ \ ");
            Console.WriteLine(@" \ \  / /__ _ __   __| | ___  ______ | \  / | __ _| |_ _  ___  | |__ | | | | | | |");
            Console.WriteLine(@"  \ \/ / _ \ '_ \ / _` |/ _ \ ______ | |\/| |/ _` | __| |/ __| |___ \| | | | | | |");
            Console.WriteLine(@"   \  /  __/ | | | (_| | (_) |       | |  | | (_| | |_| | (__   ___) | |_| | |_| |");
            Console.WriteLine(@"    \/ \___|_| |_|\__,_|\___/        |_|  |_|\__,_|\__|_|\___| |____/ \___/ \___/ ");

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("Main Menu");
                Console.WriteLine("(1) Display vending machine items");
                Console.WriteLine("(2) Purchase");
                Console.WriteLine();

                Console.WriteLine("What would you like to do? ");
                Console.WriteLine(">>");
                string input = Console.ReadLine();

                if (input == "1")
                {
                    Console.Clear();
                    machine.DisplayInventory();
                }
                else if (input == "2")
                {
                    SubMenu submenu = new SubMenu();
                    submenu.Display(machine);
                }
            }
        }