コード例 #1
0
        public Change Calculate(int cents)
        {
            int[] coins = FindCoinsForChange(cents);

            int    typeCoinsLength     = coins.Length - 1;
            string changeWithLessCoins = string.Empty;

            while (typeCoinsLength > 0) // While the value greater than 0
            {
                int  coin       = coins[typeCoinsLength];
                bool enoughCoin = _box.FindCoin(coin)?.DecreaseQuantity() ?? false;

                if (!enoughCoin)
                {
                    return(new Change(nameof(AppConsts.InsufficientCoins), AppConsts.InsufficientCoins, _box.Coins));
                }

                changeWithLessCoins += coin.Formatting();
                typeCoinsLength     -= coin;
                if (typeCoinsLength > 0)
                {
                    changeWithLessCoins += " | ";
                }
            }

            return(new Change(nameof(AppConsts.ExchangeSuccessful), AppConsts.ExchangeSuccessful, _box.Coins, changeWithLessCoins));
        }
コード例 #2
0
        public void SupplyCoins(byte value, int quantity)
        {
            var coin = _box.FindCoin(value);

            coin?.IncreaseQuantity(quantity);
        }