Esempio n. 1
0
 public void Choose(string input, BalanceSystem balanceSystem)
 {
     if (input == "cash")
     {
         _cashCollector.TakePayment(balanceSystem);
     }
     else if (input == "card")
     {
         _cardSlot.TakePayment(balanceSystem);
     }
 }
Esempio n. 2
0
        public void DispenseChange(BalanceSystem balanceSystem)
        {
            Display display = new Display();

            if (balanceSystem.balance > 0)
            {
                balanceSystem.balance = 0;
                display.DispenseChange();
            }
            else
            {
                display.NoChangeToDispense();
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 public void DisplayBalance(BalanceSystem balanceSystem)
 {
     Console.WriteLine("Your balance is: £" + balanceSystem.balance.ToString("F"));
     Console.WriteLine();
 }
Esempio n. 5
0
        public void TakePayment(BalanceSystem balanceSystem)
        {
            balanceSystem.Balance(Math.Round(Convert.ToDecimal(_keypad.TakeBalance(_display)), 2));

            _display.DisplayBalance(balanceSystem);
        }
Esempio n. 6
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();
            }
        }
Esempio n. 7
0
 public void TakePayment(BalanceSystem balanceSystem)
 {
     cardInserted = true;
 }