| Homework 4DetailsSmallBank
READ THESE DIRECTIONS CAREFULLY
-
Create a class named BankAccount.
This class should include two instance variables,
one that records the balance and another that records the name of the account holder.
You should provide code for each of the following:
- Constructor that takes a name as its only input parameter and sets the initial balance to zero.
- Constructor that takes a name and an initial balance as its two input parameters.
- An accessor method that returns the current balance of the account.
- An accessor method that returns the current name of the account.
- A mutator method that sets the name of the account to the new name in its input parameter.
- A mutator method that makes a deposit to the account by adding its input parameter
to the balance.
- A method that makes a withdrawal from the account by subtracting its input parameter
from the balance.
- Write your class so that it prohibits negative values for deposit and withdrawal
and so that it prohibits a withdrawal of an amount larger than the balance.
- Test your class thoroughly.
-
Create a second class named SmallBank.
This class should have two instance variables named account1 and account2,
each of type BankAccount. The reason this is a small bank is because it can only
have two bank accounts - we'll see how to create larger collections in chapter 4.
You should provide code for each of the following:
-
Write a class named SmallBankTester that has a method named testSmallBank.
This method should create a SmallBank object, invoke the printBankDetails method a
first time to print the first account's details, invoke the addSecondAccount method
to add the second account, and invoke the printBankDetails method a second time to
print both account details. This method doesn't need to return anything, but you
should look at the Terminal window to make sure the account details printed properly both times.
When you have completed this assignment, select "Create Jar File ..." from the File menu in BlueJ.
Check "include source" and "include Bluej project files".
Save the file with the name bassett-smallbank.jar (except use your name instead of bassett).
Then upload the "jar" file into Moodle no less than ten minutes before the start of class.
|