Exemplo n.º 1
0
        public bool SelectProduct(int position)
        {
            var stockedItem = stockItems.GetItemInformation(position);

            if (stockedItem == null || stockedItem.FirstOrDefault().Value < 1)
            {
                messageService.ChangeVendingMessage("SOLD OUT");
                return(true);
            }


            var itemPrice = stockedItem.FirstOrDefault().Key.Price;

            if (CanProductBePurchased(itemPrice))
            {
                cashBox.AddCoinsToStack(currentCoins.RemoveAllCoins());
                messageService.ChangeVendingMessage("THANK YOU");
                return(true);
            }
            else
            {
                coinReturn.RemoveAllCoins();
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool AcceptCoin(Coin InsertedCoin)
        {
            // Return Invalid Coin
            if (!InsertedCoin.IsValid)
            {
                coinReturn.AddCoinsToStack(InsertedCoin);
            }

            currentCoins.AddCoinsToStack(InsertedCoin);
            return(true);
        }
Exemplo n.º 3
0
        private bool CheckChangeCanBeGiven(decimal itemPrice)
        {
            var combinedResources = new CoinStack();

            combinedResources.AddCoinsToStack(currentCoins.GetAllCoins());
            combinedResources.AddCoinsToStack(cashBox.GetAllCoins());

            var ordered = combinedResources.GetAllCoins().OrderBy(x => x.Key.CoinWorth);

            foreach (var coinType in ordered)
            {
                var coinsAvailable = coinType.Value;
                while (itemPrice >= coinType.Key.CoinWorth && coinsAvailable > 0)
                {
                    itemPrice      -= coinType.Key.CoinWorth;
                    coinsAvailable -= 1;
                    coinReturn.AddCoinsToStack(coinType.Key);
                }
            }

            return(itemPrice == 0 ? true : false);
        }