예제 #1
0
        /// <summary>
        /// Calculates the the fewest notes and coins to be dispensed.
        /// </summary>
        /// <param name="highestDenominationInBaseUnit">The largest currency denomination value to include eg. 2000 ie £20</param>
        /// <param name="amountToDispense">The amount to dispense expressed in the currencies fractional unit.</param>
        /// <returns></returns>
        public virtual IEnumerable <MoneyStack> CountMoneyStacksToDispense(int highestDenominationInBaseUnit, int amountToDispense)
        {
            var cashCollection = new List <MoneyStack>();

            if (amountToDispense < highestDenominationInBaseUnit)
            {
                highestDenominationInBaseUnit = amountToDispense;
            }

            var moneyVault = Vault.MoneyStacks.Where(x => x.BaseValue <= highestDenominationInBaseUnit).ToList();

            foreach (MoneyStack money in moneyVault)
            {
                int quantity = amountToDispense / money.BaseValue;

                quantity = money.Quantity > quantity ? quantity : money.Quantity;

                if (quantity == 0)
                {
                    continue;
                }

                int remainder = amountToDispense % (money.BaseValue * quantity);

                MoneyStack cash = Vault.Take(money, quantity);
                cashCollection.Add(cash);

                amountToDispense -= cash.Total;

                if (remainder <= 0)
                {
                    break;
                }
            }

            return(cashCollection);
        }
예제 #2
0
 /// <summary>
 /// This will return a new instance of the money stack and reduce that stack from the stacks of money in the vaults main supply
 /// </summary>
 /// <param name="moneyStack"></param>
 /// <returns>A subset of all of the money stack that was imput.</returns>
 public abstract MoneyStack Take(MoneyStack moneyStack, int quantity);