Пример #1
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);
            }
        }
Пример #2
0
 private void DispenseSoda(int currentTransactionTotal, VmCoinBank coinBank, VmFoodSlot foodSlot, string itemToDispense, VmDisplay display)
 {
     if (_soda.Count == 0)
     {
         display.SoldOutMessage();
     }
     else if (currentTransactionTotal < SODA_COST)
     {
         display.PriceMessage(SODA_COST);
     }
     else
     {
         _soda.Remove(SODA_STRING);
         coinBank.MakeChange(currentTransactionTotal - SODA_COST);
         foodSlot.AcceptFood("Soda");
     }
 }
Пример #3
0
 private void DispenseCandy(int currentTransactionTotal, VmCoinBank coinBank, VmFoodSlot foodSlot, string itemToDispense, VmDisplay display)
 {
     if (_candy.Count == 0)
     {
         display.SoldOutMessage();
     }
     else if (currentTransactionTotal < CANDY_COST)
     {
         display.PriceMessage(SODA_COST);
     }
     else
     {
         _candy.Remove(CANDY_STRING);
         coinBank.MakeChange(currentTransactionTotal - CANDY_COST);
         foodSlot.AcceptFood("Candy");
     }
 }