Beispiel #1
0
        private bool TryExchange(MoneyCollection resultMoney)
        {
            ICountableCollection <int> exchangeResult;
            var greedyExchanger = new GreedyExchanger();

            if (greedyExchanger.TryExchange(new DecreasingIntegerCollectionMultiplier(Money.Notes, _currency.UnitFractions),
                                            _insertedCoins.Total, out exchangeResult))
            {
                resultMoney.Notes.Add(exchangeResult.Select(nominal => nominal / Money.Currency.UnitFractions));
                return(true);
            }

            resultMoney.Coins.Add(_insertedCoins);
            return(false);
        }
        private bool TryExchange(MoneyCollection resultMoney)
        {
            int valueForExchange = _insertedNotes.Total * _currency.UnitFractions;
            var money            = _cashRepository.LoadMoney(_currency);

            ICountableCollection <int> exchangeResult;
            var greedyExchanger = new GreedyExchanger();

            if (greedyExchanger.TryExchange(money.Coins, valueForExchange, out exchangeResult))
            {
                resultMoney.Coins.Add(exchangeResult);
                return(true);
            }

            resultMoney.Notes.Add(_insertedNotes);
            return(false);
        }