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(); } }
public void DisplayStock() { StockItemList stockItemList = new StockItemList(); List <StockItem> calledList = stockItemList.GetList(); Console.WriteLine("Choose which item you want to purchase by typing the ID."); for (int i = 0; i < calledList.Count; i++) { Console.WriteLine((calledList[i].GetId() + 1) + ". " + calledList[i].GetName() + " - £" + calledList[i].GetPrice().ToString("F")); } }
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); }