Cs212-Lab 4
Cs212-Lab 4
Lab Assignment 4
You will specifically apply:
arrays
ArrayList with and without Generics
traversing an ArrayList using:
o for loop
o Iterator
o for each loop (in case of Generics)
Implement the following changes within the existing classes.
Please try to adhere to the specified names.
class Account:
The class Account must keep track of the last 5 transactions.
CS 212
Page 1 of 3
class Client:
The client is now allowed to have more than one account. We use an ArrayList with
Generics.
Modify the field account. Its name is now accounts and it is of the type
ArrayList<Account>
Add a new field accountNumber (of type int).
The ArrayList is instantiated in the constructor. accountNumber is initialized to
1.
Modify the method newAccount(). Its now creates a new account (using
accountNumber) and adds it to accounts. Then accountNumber is
incremented.
Modify the method getAccount(): it has now an int parameter specifying the
index of the account. If an account with this index exists, it is returned.
Otherwise null is returned.
Modify the method printClerkPhoneNumber(): it prints for every account in
accounts:
o the accountNumber
o and the name and phone number of the clerk or no clerk for this
account
Use a for each loop.
Modify the method printBalance(): it prints for every account in accounts:
o the accountNumber
o the balance of this account
Use the Iterator.
Modify the methods payIn(), takeOff()and setClerk(). They receive an
additional parameter denoting the index of the account to be used. If the
index is not valid, the first account (index 0) is used if an account exists at all.
class Clerk:
A clerk should know for which accounts he is responsible. This will be implemented
without Generics.
CS 212
Page 2 of 3
in the method setClerk(): call the method addAccount of the clerk that is now
responsible for the account.
Note: The list of accounts in the Clerk class might contain accounts twice or more
often and also contain accounts, the client is no longer responsible for. We will
repair this in a future lab.
CS 212
Page 3 of 3