Exemplo n.º 1
0
        public string Cash(IBanknote banknote)
        {
            var value             = int.Parse(banknote.Value);
            var numberOfBanknotes = value / nominalValue;

            if (IsExisitsWholeRemainder(value, numberOfBanknotes))
            {
                var newBanknote = new Banknote(banknote.Currency, (value - nominalValue * numberOfBanknotes).ToString());
                return(nominalValue + "*" + numberOfBanknotes + " " + nextHandler.Cash(newBanknote));
            }
            if (numberOfBanknotes == 0)
            {
                if (nextHandler != null)
                {
                    var newBanknote = new Banknote(banknote.Currency, (value % nominalValue).ToString());
                    return(nextHandler.Cash(newBanknote));
                }
                return(banknote.Currency.ToString());
            }
            if (nextHandler != null)
            {
                var newBanknote = new Banknote(banknote.Currency,
                                               (int.Parse(banknote.Value) % nominalValue).ToString());
                return(nominalValue + "*" + numberOfBanknotes + " " + nextHandler.Cash(newBanknote));
            }
            if (nextHandler == null && value % nominalValue != 0)
            {
                return(numberOfBanknotes * 10 + value % nominalValue + " - не валидная сумма");
            }
            return(nominalValue + "*" + numberOfBanknotes + " " + banknote.Currency.ToString());
        }
Exemplo n.º 2
0
        public override Banknote[] CashOut(CurrencyType c, ref uint v)
        {
            if (c == CurrencyType.Ruble)
            {
                if (v / 10 > 0)
                {
                    var count = v / 10;
                    var list  = new Banknote[count];

                    for (int i = 0; i < count; i++)
                    {
                        var bancnote = new Banknote(c, 10);

                        list[i] = bancnote;
                    }
                    v -= count * 10;
                    return(list.Concat(base.CashOut(c, ref v)).ToArray());
                }

                return(base.CashOut(c, ref v));
            }
            return(base.CashOut(c, ref v));
        }