Example #1
0
 public static void ListPurchases(Vending_Machine machine)
 {
     for (int i = 0; i < machine.GetList().Count; i++)
     {
         Console.WriteLine($"{i + 1}: {machine.GetList()[i].GetName()}");
     }
 }
Example #2
0
        public static void ConsumeProducts(Vending_Machine machine)
        {
            Console.WriteLine("You have purchased so far:");
            ListPurchases(machine);
            Console.WriteLine();
            Console.WriteLine("What would you like to consume?");
            Console.WriteLine();
            Console.Write("Choice: ");


            bool realNumber = Int32.TryParse(Console.ReadLine(), out int choice);

            if (realNumber && choice > 0)
            {
                if (machine.GetList()[choice - 1] is Drink)
                {
                    Console.WriteLine($"You guzzle down the {machine.GetList()[choice - 1].GetName()}. Refreshing... in a way.");
                }
                else if (machine.GetList()[choice - 1] is Food)
                {
                    Console.WriteLine($"You eat the {machine.GetList()[choice - 1].GetName()}. It's probably nutritious. Probably.");
                }
                else if (machine.GetList()[choice - 1] is Snack)
                {
                    Console.WriteLine($"You munch on the {machine.GetList()[choice - 1].GetName()}. Delicious! ...if you don't think too much about it.");
                }
                machine.RemoveProductFromList(choice - 1);
            }
            else
            {
                Console.WriteLine("Illegal input.");
            }
        }
Example #3
0
        public static void InspectProduct(Vending_Machine machine)
        {
            Console.WriteLine("You have purchased so far:");
            ListPurchases(machine);
            Console.WriteLine();
            Console.WriteLine("What would you like to look at?");
            Console.WriteLine();
            Console.Write("Choice: ");

            bool realNumber = Int32.TryParse(Console.ReadLine(), out int choice);

            string textChoice = machine.GetList()[choice - 1].GetName();



            Console.WriteLine(Data.descriptions[textChoice]);
        }
Example #4
0
        public static void PurchaseProducts(Vending_Machine machine)
        {
            string choice;
            int    price;
            //string[] choiceProduct;
            int purchase = -1;

            ListProducts();

            Console.WriteLine();
            Console.Write("What would you like to purchase? ");

            choice = Console.ReadLine().ToUpper();


            for (int i = 0; i < Data.vendingMenu.GetLength(0); i++)
            {
                if (Data.vendingMenu[i, 0] == choice)
                {
                    purchase = i;
                }
            }


            if (purchase == -1)
            {
                Console.WriteLine("Sorry, that's not a Quick-Snack registered product.");
            }
            else
            {
                price = Convert.ToInt32(Data.vendingMenu[purchase, 3]);
                if (price > machine.GetAvailableMoney())
                {
                    Console.WriteLine("Sorry, you can't afford that with currently available funds.");
                }
                else
                {
                    Console.WriteLine($"You chose {Data.vendingMenu[purchase, 0]}: {Data.vendingMenu[purchase, 2]} for {price}kr.");
                    machine.ChangeAvailableMoney(-price);


                    AddPurchase(purchase, machine);
                }
            }
        }
Example #5
0
        static void Main()
        {
            var vendingMachine = new Vending_Machine();

            var coke     = new Product("Coke", ProductCategory.Beverage, 1.25);
            var pepsi    = new Product("Pepsi", ProductCategory.Beverage, 1.00);
            var drPepper = new Product("Dr Pepper", ProductCategory.Beverage, 1.25);

            vendingMachine.AddProduct(coke, 25);
            vendingMachine.AddProduct(pepsi, 35);
            vendingMachine.AddProduct(drPepper, 45);

            Console.WriteLine("Please insert money into the machine then make your selection.");
            Console.WriteLine("For more information, type `help`.");

            string line;
            bool   atMachine = true;

            while (atMachine)
            {
                Console.WriteLine($"Balance: {vendingMachine.Balance:N2}");
                line = Console.ReadLine();

                switch (line.ToLower())
                {
                case "exit":
                    atMachine = false;
                    break;

                case "help":
                    PrintHelp();
                    break;

                case "list":
                    vendingMachine.ListProducts();
                    break;

                default:
                    CheckCommand(line.ToLower());
                    break;
                }
            }
        }
Example #6
0
        public static void AddPurchase(int product, Vending_Machine machine)
        {
            if (Data.vendingMenu[product, 0].StartsWith("D"))    //Is a drink
            {
                machine.AddProductToList(new Drink(Data.vendingMenu[product, 2]));
            }
            else if (Data.vendingMenu[product, 0].StartsWith("F"))    //Is a food
            {
                machine.AddProductToList(new Food(Data.vendingMenu[product, 2]));
            }
            else if (Data.vendingMenu[product, 0].StartsWith("S"))    //Is a snack
            {
                machine.AddProductToList(new Snack(Data.vendingMenu[product, 2]));
            }
            else
            {
                Console.WriteLine("Unrecognized format.");
            }

            Console.WriteLine($"You receive {Data.vendingMenu[product, 2]}.");
        }
Example #7
0
        public static int DepositMoney(Vending_Machine machine)                                                //Turn this into quick keypresses on a list later
        {
            int deposited = 0;
            int total     = 0;

            Console.WriteLine("Choose money to deposit. Machine will not accept non-legal tender. Press Return or Escape to finish.");
            Console.WriteLine();

            for (int i = 0; i < machine.moneyArray.Length; i++)
            {
                Console.WriteLine($"{i + 1}: {machine.moneyArray[i]}kr");
            }

            do
            {
                machine.keyPressed = Console.ReadKey(true);      //Store the key pressed
                deposited          = 0;

                if ((machine.keyPressed.Key == ConsoleKey.D1) || (machine.keyPressed.Key == ConsoleKey.NumPad1))
                {
                    deposited = 1;
                }
                else if ((machine.keyPressed.Key == ConsoleKey.D2) || (machine.keyPressed.Key == ConsoleKey.NumPad2))
                {
                    deposited = 5;
                }
                else if ((machine.keyPressed.Key == ConsoleKey.D3) || (machine.keyPressed.Key == ConsoleKey.NumPad3))
                {
                    deposited = 10;
                }
                else if ((machine.keyPressed.Key == ConsoleKey.D4) || (machine.keyPressed.Key == ConsoleKey.NumPad4))
                {
                    deposited = 20;
                }
                else if ((machine.keyPressed.Key == ConsoleKey.D5) || (machine.keyPressed.Key == ConsoleKey.NumPad5))
                {
                    deposited = 50;
                }
                else if ((machine.keyPressed.Key == ConsoleKey.D6) || (machine.keyPressed.Key == ConsoleKey.NumPad6))
                {
                    deposited = 100;
                }
                else if ((machine.keyPressed.Key == ConsoleKey.D7) || (machine.keyPressed.Key == ConsoleKey.NumPad7))
                {
                    deposited = 500;
                }
                else if ((machine.keyPressed.Key == ConsoleKey.D8) || (machine.keyPressed.Key == ConsoleKey.NumPad8))
                {
                    deposited = 1000;
                }
                else if ((machine.keyPressed.Key == ConsoleKey.Escape) || (machine.keyPressed.Key == ConsoleKey.Enter))
                {
                    Console.WriteLine("Thank you for depositing your money!");
                }
                else
                {
                    Console.WriteLine("Illegal command.");
                }

                total += deposited;

                if (deposited > 0)
                {
                    Console.WriteLine($"You deposit {deposited} for a total of {total}kr so far.");
                }
            } while (!((machine.keyPressed.Key == ConsoleKey.Escape) || (machine.keyPressed.Key == ConsoleKey.Enter)));

            Console.WriteLine($"You have deposited {total}kr.");

            return(total);
        }
Example #8
0
 public static void PayBack(Vending_Machine machine)
 {
     ReturnMoney(machine.GetAvailableMoney());
     machine.SetAvailableMoney(0);
 }
Example #9
0
        static void Main(string[] args)
        {
            Vending_Machine QS = new Vending_Machine();

            Console.WriteLine();
            Console.WriteLine("Welcome to Quick-Snack, your premier choice for avoiding starvation death!");
            Console.WriteLine();
            Console.WriteLine("To make a purchase, deposit as much money as you like \ninto the marked receptacles, then choose any product from the menu.");
            Console.WriteLine();
            Console.WriteLine("Enjoy your snack, and remember: The Quick-Snack Corporation is not held liable \nfor any injury or death caused by using Quick-Snack!");
            Console.ReadLine();
            Console.Clear();



            while (true)
            {
                Console.WriteLine();
                PrintMenu();
                Console.WriteLine();

                Console.WriteLine($"You have {QS.GetAvailableMoney()}kr available for purchases.");
                Console.WriteLine();

                Console.Write("Choice: ");

                QS.keyPressed = Console.ReadKey(true);      //Store the key pressed

                Console.Clear();
                Console.WriteLine();

                switch (QS.keyPressed.Key)
                {
                case ConsoleKey.M:
                    QS.ChangeAvailableMoney(DepositMoney(QS));
                    break;

                case ConsoleKey.L:
                    ListProductsWithoutSelectors();
                    break;

                case ConsoleKey.P:
                    PurchaseProducts(QS);
                    break;

                case ConsoleKey.I:
                    InspectProduct(QS);
                    break;

                case ConsoleKey.C:
                    ConsumeProducts(QS);
                    break;

                case ConsoleKey.R:
                    PayBack(QS);
                    break;

                case ConsoleKey.Q:
                    Quit();
                    break;

                case ConsoleKey.Escape:
                    Quit();
                    break;


                default:
                    Console.WriteLine("Illegal input.");
                    break;
                }

                Console.ReadLine();
                Console.Clear();
            }
        }