Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var             input           = "";
            Display         display         = new Display();
            Keypad          keypad          = new Keypad();
            CashCollector   cashCollector   = new CashCollector(display, keypad);
            CardSlot        cardSlot        = new CardSlot(display, keypad);
            PaymentMethod   paymentMethod   = new PaymentMethod(cashCollector, cardSlot);
            Dispenser       dispenser       = new Dispenser();
            StockItemList   stockItemList   = new StockItemList();
            ChangeDispenser changeDispenser = new ChangeDispenser();
            BalanceSystem   balanceSystem   = new BalanceSystem();

            do
            {
                display.Greeting();
                input = keypad.TakeInput();
                paymentMethod.Choose(input, balanceSystem);
            } while (!(input == "card" || input == "cash"));

            display.DisplayStock();
            dispenser.DispenseStock(keypad.TakeStockItem(), stockItemList, cardSlot, keypad, changeDispenser, display, balanceSystem);
        }
Exemplo n.º 2
0
 public CashCollector(Display display, Keypad keypad)
 {
     _display = display;
     _keypad  = keypad;
 }
Exemplo n.º 3
0
        public void DispenseStock(int stockId, StockItemList stockItemList, CardSlot cardSlot, Keypad keypad, ChangeDispenser changeDispenser, Display display, BalanceSystem balanceSystem)
        {
            List <StockItem> calledList = stockItemList.GetList();

            for (int i = 0; i < calledList.Count; i++)
            {
                if ((stockId - 1) == calledList[i].GetId() && (cardSlot.cardInserted == true || balanceSystem.balance >= calledList[i].GetPrice()))
                {
                    Console.WriteLine("Item has been dispensed.");
                    balanceSystem.Balance(-calledList[i].GetPrice());
                }
                else if ((stockId - 1) == calledList[i].GetId() && (cardSlot.cardInserted == true || balanceSystem.balance < calledList[i].GetPrice()))
                {
                    Console.WriteLine("Not enough money has been deposited to buy this item.");
                }
            }

            Console.WriteLine("Type 'again' to buy another item, or press enter to dispense your remaining balance.");
            if (keypad.TakeInput() == "again")
            {
                display.DisplayBalance(balanceSystem);
                display.DisplayStock();
                DispenseStock(keypad.TakeStockItem(), stockItemList, cardSlot, keypad, changeDispenser, display, balanceSystem);
            }
            else
            {
                changeDispenser.DispenseChange(balanceSystem);
                Console.ReadLine();
            }
        }
Exemplo n.º 4
0
 public CardSlot(Display display, Keypad keypad)
 {
     _display = display;
     _keypad  = keypad;
 }