Example #1
0
 public VmCoinBank(List <string> coinsInBank, VmCoinValidator validator, VmCoinSlot coinSlot, VmCoinReturn coinReturn)
 {
     _coinsInBank = coinsInBank;
     _validator   = validator;
     _coinSlot    = coinSlot;
     _coinReturn  = coinReturn;
 }
Example #2
0
        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);
            }
        }
        private static void StartMachine()
        {
            IConsole        console       = new VmGetInput();
            VmCoinValidator coinValidator = new VmCoinValidator();
            VmCoinReturn    coinReturn    = new VmCoinReturn();
            VmCoinSlot      coinSlot      = new VmCoinSlot(new List <string>(), coinReturn, coinValidator);
            VmFoodDispenser foodDispenser = new VmFoodDispenser();
            VmFoodSlot      foodSlot      = new VmFoodSlot();
            VmCoinBank      coinBank      = new VmCoinBank(new List <string>(), coinValidator, coinSlot, coinReturn);
            VmDisplay       display       = new VmDisplay(console);
            VmUi            mainUi        = new VmUi(coinSlot, coinValidator, coinReturn, foodDispenser, foodSlot, coinBank, console, display);

            coinBank.Restock();
            foodDispenser.Restock();
            mainUi.ShowMainUi();
        }
Example #4
0
        public VmUi(VmCoinSlot coinSlot, VmCoinValidator coinValidator, VmCoinReturn coinReturn, VmFoodDispenser foodDispenser, VmFoodSlot foodSlot, VmCoinBank coinBank, IConsole console, VmDisplay display)
        {
            _coinSlot      = coinSlot;
            _coinValidator = coinValidator;
            _coinReturn    = coinReturn;
            _foodDispenser = foodDispenser;
            _foodSlot      = foodSlot;
            _coinBank      = coinBank;
            _console       = console;
            _display       = display;

            _showMainUiWasCalled       = false;
            _showInsertCoinUiWasCalled = false;
            _showDisplayUiWasCalled    = false;
            _showCoinReturnUiWasCalled = false;
            _showFoodSlotUiWasCalled   = false;
            _showRedirectUiWasCalled   = false;
        }
Example #5
0
 public VmCoinSlot(List <string> listOfCoinsInCurrentTransaction, VmCoinReturn coinReturn, VmCoinValidator validator)
 {
     _listOfCoinsInCurrentTransaction = listOfCoinsInCurrentTransaction;
     _coinReturn = coinReturn;
     _validator  = validator;
 }