public bool Dispense(string itemToDispense, VmCoinValidator validator, VmCoinBank coinBank, VmFoodSlot foodSlot, VmDisplay display) { int currentTransactionTotal = validator.GetCurrentTransactionTotal(); if (itemToDispense == SODA_STRING && _soda.Count == 0 || itemToDispense == CHIPS_STRING && _chips.Count == 0 || itemToDispense == CANDY_STRING && _candy.Count == 0) { display.SoldOutMessage(); return(false); } if (itemToDispense == SODA_STRING && currentTransactionTotal < SODA_COST) { display.PriceMessage(SODA_COST); return(false); } if (itemToDispense == CHIPS_STRING && currentTransactionTotal < CHIPS_COST) { display.PriceMessage(CHIPS_COST); return(false); } if (itemToDispense == CANDY_STRING && currentTransactionTotal < CANDY_COST) { display.PriceMessage(CANDY_COST); return(false); } switch (itemToDispense) { case SODA_STRING: DispenseSoda(currentTransactionTotal, coinBank, foodSlot, itemToDispense, display); display.ThankYouMessage(); validator.CompleteTransaction(); return(true); case CHIPS_STRING: DispenseChips(currentTransactionTotal, coinBank, foodSlot, itemToDispense, display); display.ThankYouMessage(); validator.CompleteTransaction(); return(true); case CANDY_STRING: DispenseCandy(currentTransactionTotal, coinBank, foodSlot, itemToDispense, display); display.ThankYouMessage(); validator.CompleteTransaction(); return(true); default: return(false); } }
public void ShowMainUi() { if (!Console.IsOutputRedirected) { Console.Clear(); } Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("______________________VENDING MACHINE_______________________"); Console.WriteLine("| (I) Insert Coin (R) Refund |"); Console.WriteLine("| |"); Console.WriteLine("| (S) Soda: 1.00 (H) Chips: .50 (C) Candy: .65 |"); Console.WriteLine("| |"); Console.WriteLine("| (T) Take Item (" + _foodSlot.GetListOfItemsInSlot().Count + " items) (N) Coin Return (" + _coinReturn.CheckReturn().Count + " items) |"); Console.WriteLine("____________________________________________________________"); Console.WriteLine(""); if (_coinValidator.GetCurrentTransactionTotal() > 0) { _display.CurrentTotalMessage(_coinValidator.GetCurrentTransactionTotal()); } else if (!_coinBank.CanMakeChange()) { _display.ExactChangeMessage(); } else { _display.InsertCoinMessage(); } Console.WriteLine("Enter the letter of the item you wish to access"); Console.WriteLine("-OR-"); Console.WriteLine("Enter 'Display' at any time to check the display, or 'E' to Exit."); _showMainUiWasCalled = true; _entry = _console.ReadLine(); switch (_entry) { case ("I"): ShowInsertCoinUi(); break; case ("R"): _coinSlot.GiveRefund(); ShowCoinReturnUi(); break; case ("S"): case ("H"): case ("C"): if (_foodDispenser.Dispense(_entry, _coinValidator, _coinBank, _foodSlot, _display)) { Console.WriteLine("You hear a *thunk* as an item lands in the Food Slot."); ShowFoodSlotUi(); } else { Console.WriteLine("Nothing happens."); ShowRedirectUi(); } break; case ("T"): ShowFoodSlotUi(); break; case ("N"): ShowCoinReturnUi(); break; case ("DISPLAY"): ShowDisplayUi(); break; case ("E"): break; default: if (!Console.IsOutputRedirected) { InvalidInput(); } break; } }
public void DetermineChange() { _validator.GetCurrentTransactionTotal(); }