Ejemplo n.º 1
0
        /// <summary>
        /// method purchases products from VendingController.
        /// If there is a problem with the purchase, there will be messages shown
        /// Otherwise the product and it usage will be shown
        /// </summary>
        /// <param name="vm">the VendingController instance</param>
        private static void Buy(VendingController vm)
        {
            Console.WriteLine(vm.ShowAll());
            Console.WriteLine("Choose product to buy: ");
            int wantedProduct = -1;
            var parseOk       = int.TryParse(Console.ReadLine(), out wantedProduct);

            if (parseOk)
            {
                Console.WriteLine(vm.Purchase(wantedProduct));
            }
            else
            {
                Console.WriteLine("Problem with choice, try again!");
            }

            Console.WriteLine("Your balance is: " + vm.Payment + " kr.\n");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Main method with a loop for menu choices
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            VendingController vm = new VendingController(true);

            Console.WriteLine("Welcome to Vending Machine!");
            bool finished = false;

            while (!finished)
            {
                ShowMenu();

                Console.WriteLine("Your current balance is " + vm.Payment + " kr.");
                Console.Write("My Choice: ");
                char choice = Console.ReadKey(true).KeyChar;
                Console.WriteLine("\n--------------------");

                switch (choice)
                {
                /*case '0':
                 *  //menu automatically shows... default will do
                 *  break;*/
                case '1':
                    Console.WriteLine(vm.ShowAll());
                    break;

                case '2':
                    InsertCash(vm);
                    break;

                case '3':
                    Buy(vm);
                    break;

                case '4':
                    Console.WriteLine(vm.EndTransaction());
                    finished = true;
                    break;

                default:
                    break;
                }
            }
        }