示例#1
0
 public void Dispense(Currency cur)
 {
     if (cur.Amount >= 100)
     {
         int num       = cur.Amount / 100;
         int remainder = cur.Amount % 100;
         Console.WriteLine("Dispensing " + num + " Rs. 100 note");
         if (remainder != 0)
         {
             nextDispenser.Dispense(new Currency(remainder));
         }
     }
     else
     {
         nextDispenser.Dispense(cur);
     }
 }
示例#2
0
        public ICashDispenser WithDraw(string name, decimal amount)
        {
            ICashDispenser cashDispenser = Factory.CreateCashDispenser();

            IAccount     account  = GetAccountByName(name);
            ITransaction withDraw = new WithDraw()
            {
                Account = account,
                Amount  = amount
            };

            if (account.Balance < amount)
            {
                cashDispenser.IsSufficientBalance = false;
                return(cashDispenser);
            }
            else
            {
                cashDispenser.IsSufficientBalance = true;
            }

            int[] bills = _dab.GetBills();

            for (int i = 0; i < bills.Length; i++)
            {
                if (!(amount < bills[i]))
                {
                    cashDispenser.NumberOfBills[i] = (int)amount / bills[i];
                    if (cashDispenser.NumberOfBills[i] > _dab.NumberOfBills[i])
                    {
                        cashDispenser.NumberOfBills[i] = _dab.NumberOfBills[i];
                    }
                    amount -= bills[i] * cashDispenser.NumberOfBills[i];
                }
            }

            if (amount > 10)
            {
                cashDispenser.IsSufficientCash = false;
                return(cashDispenser);
            }
            else if (amount > 0 && amount < 10)
            {
                cashDispenser.IsValidAmount = false;
                return(cashDispenser);
            }
            else
            {
                cashDispenser.IsSufficientCash = true;
                cashDispenser.IsValidAmount    = true;
                cashDispenser.Dispense(_dab);
                withDraw.Execute();
                return(cashDispenser);
            }
        }
示例#3
0
文件: Atm.cs 项目: Josbleuet/ttd
        public bool DoWithdrawal(Account account, int amount)
        {
            var transactionBancaire = transactionFactory.Create(account, amount);

            if (transactionBancaire.Validate())
            {
                transactionBancaire.Process();

                try
                {
                    cashDispenser.Dispense(amount);
                    return(true);
                }
                catch (OutOfMoneyException e)
                {
                    transactionBancaire.Rollback();
                }
            }
            return(false);
        }