示例#1
0
        public UserInterface()
        {
            VendingMachineFileReader          fr        = new VendingMachineFileReader();
            Dictionary <string, List <Item> > Inventory = fr.ReadInventory();

            this.vm           = new VendingMachine(Inventory);
            this.productCodes = new List <string>();
        }
示例#2
0
        public void Display()
        {
            string targetPath = Directory.GetCurrentDirectory();
            string fileName   = "vendingmachine.csv";
            string fullPath   = Path.Combine(targetPath, fileName);

            inventory = vmfr.ReadInventory(fullPath);
            VendingMachine vm = new VendingMachine(inventory);

            Console.WriteLine("*****************\nVendo-Matic 500\n*****************");

            while (true)
            {
                bool firstResponse = false;
                while (firstResponse == false)
                {
                    Console.WriteLine("-----------------\nMain Menu\n-----------------\n[1] Display Vending Machine Inventory\n[2] Purchase an Item\n[3] Quit\n");
                    string mainMenuResponse = Console.ReadLine();
                    if (mainMenuResponse != "1" && mainMenuResponse != "2" && mainMenuResponse != "3")
                    {
                        Console.WriteLine("Error: Invalid Response.  Please enter either 1 or 2");
                    }
                    else if (mainMenuResponse == "1")
                    {
                        firstResponse = true;
                        DisplayInventory();
                    }
                    else if (mainMenuResponse == "2")
                    {
                        firstResponse = true;
                        DisplayPurchaseMenu(vm);
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }
        }