Exemple #1
0
        //Method that processes the request or passes it to the next handler
        public virtual bool DispenseRequest(int amount, ATM currATM, ref int sum_dispense)
        {
            if (amount >= Denomination)
            {
                var num       = GetQuantity();
                var remainder = amount;
                while (remainder >= Denomination && num > 0 &&
                       currATM.GetCurrNotesAmount() + 1 <= currATM.GetMaxNotesAmount())
                {
                    remainder -= Denomination;
                    num--;
                }

                //added
                sum_dispense += Denomination * (GetQuantity() - num);
                Quantity     -= num;
                //added

                if (remainder != 0)
                {
                    return(next.DispenseRequest(remainder, currATM, ref sum_dispense));
                }

                return(true);
            }
            else
            {
                return(next.DispenseRequest(amount, currATM, ref sum_dispense));
            }
        }
Exemple #2
0
        //Method that processes the request or passes it to the next handler
        public virtual bool DepositRequest(int amount, int denom, Account currAccount, ATM currATM, ref int sum_deposit)
        {
            if (amount + currATM.GetCurrNotesAmount() > currATM.GetMaxNotesAmount())
            {
                return(false);
            }
            else if (denom == Denomination)
            {
                //то добавляем в ATM -> новое количество купюр
                addNewBills(amount);

                //добавляем к текущему количеству купюр
                currATM.SetCurrNotesAmount(amount);

                //это сумма денег, выполняем транзакцию
                int currTransactionSum = amount * denom;

                sum_deposit += currTransactionSum;

                return(true);
            }
            else
            {
                return(next.DepositRequest(amount, denom, currAccount, currATM, ref sum_deposit));
            }
        }