Ejemplo n.º 1
0
        private static void bulkBuy(List <Soda> stock, Cashbox cash)
        {
            listSoda(stock);
            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($"how many {stock[i]._name} would you like?");
                string input2 = Console.ReadLine();
                if (int.TryParse(input2, out var amount))
                {
                    if (stock[i]._storage < amount)
                    {
                        Console.WriteLine($"{stock[i]._name} does not have enough in stock");
                        return;
                    }
                    if (stock[i]._price * amount > 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 * amount && stock[i]._storage != 0)
                    {
                        cash.purchase(stock[i]._price * amount, stock[i]._name, amount);
                        stock[i]._storage -= amount;
                    }
                }
            }
            else
            {
                Console.WriteLine("invalid input\n");
            }
        }
Ejemplo 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;
        }
Ejemplo 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;
            }
        }
Ejemplo 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);
                }
            }
        }
Ejemplo n.º 5
0
 public void HandleSoda(Sodamachine sm, Cashbox cash)
 {
     Soda.buySoda(Stock, sm, cash);
 }