1. In the Account class, write a method called transferTo , which transfers mone
ID: 3613390 • Letter: 1
Question
1. In theAccount class, write a method calledtransferTo, which transfers money between 2
accounts. Themethod takes 2 parameters. The 1st parameter is the amount of moneythat
needs to betransferred, and the 2nd parameter is a reference to theAccount that will receive
the money. Theaccount from which the money is withdrawn from (i.e. the accountthat is
giving themoney) is the Account object that is performingthe method.
YourtransferTo method must use (call) thewithdraw and deposit method.
Your methodmust work according to the following description and method header(you must
copy this intoyour Account class):
/**transfer money (amount dollars) from this account to thereceiver account;
* if amount < 0 then nothinghappens;
* if the sending account does not have enoughmoney (this includes the amount to send
and the transactionfee),then no money will be transferred and no transaction fee
will be charge;
* /
publicvoid transferTo(double amount, Account receiver)
{
//WRITE YOUR CODE HERE
}
2. Then, inthe AccountTester class, make sure your methodworks according to the comment.
Here is asimple example of using the transferTo method, butyou will need to do more
testing to besure that the method is working properly:
//Atthe start, Adam has $500 and Betty has $0
Account a1 = new account(“Adam”);
Account a2 = new account(“Betty”);
//Nowtransfer $100 from Adam to Betty
A1.transferTo(100,a2)
//Adamshould have $398.5 (transaction fee $1.5),
//andBetty should have $100
System.out.println(a1.getOwner() + “ has$” a1.getBalance());
System.out.println(a2.getOwner() + “ has$” a2.getBalance());