Esempio n. 1
0
        public void addCredit(Sodamachine sm)
        {
            Console.WriteLine("amount:");
            string input = Console.ReadLine();
            int    amount;

            if (int.TryParse(input, out amount))
            {
                _credit += amount;
                Console.WriteLine($"you have {_credit} credit.\n");
            }
            else
            {
                Console.WriteLine("invalid input\n");
            }
            sm.AddCredit = false;
        }
Esempio n. 2
0
        public static void buySoda(List <Soda> stock, Sodamachine sm, Cashbox cash)
        {
            listSoda(stock);
            Console.WriteLine("bulk: type <bulk> top buy several sodas");
            string input = Console.ReadLine();

            if (int.TryParse(input, out var index))
            {
                if (index >= stock.Count + 1)
                {
                    Console.WriteLine("invalid input\n");
                    return;
                }
                int i = index - 1;
                Console.WriteLine($"you have chosen: {stock[i]._name}");
                if (stock[i]._price > cash.getCred())
                {
                    Console.WriteLine("you dont have enough credit.\n" +
                                      " please add some by using command <i> followed by desired amount.");
                }
                if (stock[i]._storage == 0)
                {
                    Console.WriteLine($"{stock[i]._name} is out of stock.");
                }
                if (cash.getCred() >= stock[i]._price && stock[i]._storage != 0)
                {
                    cash.purchase(stock[i]._price, stock[i]._name, 1);
                    stock[i]._storage--;
                }
                else
                {
                    Console.WriteLine("invalid input\n");
                }
            }
            if (input.ToLower() == "bulk")
            {
                bulkBuy(stock, cash);
            }


            sm.BuySoda = false;
        }
Esempio n. 3
0
        // public bool GetStatus()
        // {
        //     return _machineOn;
        // }
        public void HandleCmd(string input, Sodamachine sm, Cashbox cash)
        {
            switch (input)
            {
            case "h":
                GetHelp();
                break;

            case "i":
                AddCredit = true;
                break;

            case "q":
                _machineOn = false;
                Console.WriteLine("shutting down....");
                break;

            case "b":
                BuySoda = true;
                break;

            case "r":
                cash.returnCred();
                break;

            case "s":
                showStock(Stock);
                break;

            case "c":
                Console.WriteLine($"you have {cash.getCred()} credit");
                break;

            default:
                Console.WriteLine("Invalid command");
                break;
            }
        }
Esempio n. 4
0
        static void Main()
        {
            var sm   = new Sodamachine();
            var cash = new Cashbox(0);

            sm.StartMachine();
            sm.Setup();
            while (sm._machineOn)
            {
                var input = Console.ReadLine();
                if (input != null)
                {
                    sm.HandleCmd(input.ToLower(), sm, cash);
                }
                if (sm.AddCredit)
                {
                    cash.addCredit(sm);
                }
                if (sm.BuySoda)
                {
                    sm.HandleSoda(sm, cash);
                }
            }
        }
Esempio n. 5
0
 public void HandleSoda(Sodamachine sm, Cashbox cash)
 {
     Soda.buySoda(Stock, sm, cash);
 }