Transferring Money
File Account.java contains a
definition for a simple bank account class with methods to withdraw, deposit,
get the balance and account number, and print a summary. (This is very much
like lab 1.) Save it to your directory and study it to see how it works. Then
write the following additional code:
- Add a method public void transfer(Account acct,
double amount) to the Account class that allows the user to transfer funds
from one bank account to another. If acct1 and acct2 are Account
objects, then the call acct1.transfer(acct2,957.80) should transfer
$957.80 from acct1 to acct2.
- Write a class TransferTest with a main method that creates
two bank account objects and enters a loop that does the following:
- Asks if the user would like to transfer from account1
to account2, transfer from account2 to account1, or quit.
- If a transfer is chosen, asks the amount of the
transfer, carries out the operation, and prints the new balance for each
account.
- Repeats until the user asks to quit, then prints
a summary for each account.
Go back to lab2 index
page