Пример #1
0
 public void Deposit(CoinService service)
 {
     foreach (var coin in _coins)
     {
         service.Insert(coin.Key, coin.Value);
     }
     _coins.Clear();
 }
Пример #2
0
        private int ReturnCoin(CoinService service, Coin coin, int amount)
        {
            int dispensedCoins = Math.Min(amount / CoinValue(coin), Stored(coin));

            service.Insert(coin, dispensedCoins);
            RemoveFromService(coin, dispensedCoins);

            return(dispensedCoins);
        }
Пример #3
0
        public void Return(CoinService service, int amount)
        {
            int returnedQuarters = ReturnCoin(service, Coin.Quarter, amount);

            amount -= returnedQuarters * CoinValue(Coin.Quarter);

            int returnedDimes = ReturnCoin(service, Coin.Dime, amount);

            amount -= returnedDimes * CoinValue(Coin.Dime);

            int returnedNickels = ReturnCoin(service, Coin.Nickel, amount);

            amount -= returnedNickels * CoinValue(Coin.Nickel);

            int returnedPennies = ReturnCoin(service, Coin.Penny, amount);

            amount -= returnedPennies * CoinValue(Coin.Penny);
        }