Exemple #1
0
 public static void InsertCoins(
     this IVendingMachineService service,
     CoinType coinType,
     int numberOfCoins
     )
 {
     for (var i = 0; i < numberOfCoins; i++)
     {
         service.InsertCoinAsync(coinType.ToDecimal());
     }
 }
Exemple #2
0
        private static (decimal rest, int coinAmount) GetCoinChange(
            this decimal val,
            CoinType coinType)
        {
            var coinTypeVal = coinType.ToDecimal();
            var coins       = 0;


            while (val >= coinTypeVal)
            {
                coins = coins + 1;
                val   = val - coinTypeVal;
            }

            return(val, coins);
        }
Exemple #3
0
        private decimal ProcessReturnWallet(
            Dictionary <CoinType, Stack <Coin> > machineWallet,
            Dictionary <CoinType, Stack <Coin> > returnWallet,
            CoinType coinType,
            decimal changeVal)
        {
            var coinTypeVal = coinType.ToDecimal();

            while (changeVal >= coinTypeVal && machineWallet[coinType].Count > 0)
            {
                var fiftyCentCoin = machineWallet[coinType].Pop();
                returnWallet[coinType].Push(fiftyCentCoin);

                changeVal = changeVal - coinTypeVal;
            }

            return(changeVal);
        }
Exemple #4
0
 public Coin(CoinType coinType)
 {
     Name  = coinType;
     Value = coinType.ToDecimal();
 }