public void TestTransferMoney() { Customer oscar = new Customer("Oscar"); Account savings = new Account(Account.SAVINGS); Account checkings =new Account(Account.CHECKING); oscar.OpenAccount(savings); oscar.OpenAccount(checkings); savings.Deposit(4000); checkings.Deposit(500); oscar.transfer(checkings, savings, 500); Assert.AreEqual(3500, savings.getBalance()); Assert.AreEqual(1000, checkings.getBalance()); }
public void transfer(Account accountTo, Account accountFrom, int amount) { if (amount <= 0) return; if (accountFrom.getBalance() < amount) return; try { lock (lockobject) { accountFrom.Withdraw(amount, String.Format("Trasfer to account {0}", accountTo.AccountNumber())); accountTo.Deposit(amount, String.Format("Trasfer from account {0}", accountFrom.AccountNumber())); } } catch (Exception e) { throw (e); } }