Activity 3.5 - Using an array of a reference type
Topic
In this activity you will develop a class GroupRecord which uses the class
you wrote for the last activity.
Materials
In addition to the Solution document, the project for this activity contains
the classes:
- GroupRecord, a class so far empty but for comments!
- Member, instances of which represent members of a local conservation
group. This is the class
you wrote in Activity 3.4.
- GroupRecordTest, which will test your GroupRecord class when you have
written it.
Task
You are asked to develop a class an instance of which will maintain a list of
Member objects in an array, and provide methods to locate and access the stored
objects.
The class requires:
- an array of Member objects, with a default size of 100.
- an instance variable to record how many members are currently listed.
- a single zero-argument constructor that initialises the array variable to
a new array of the default size, and the other variable to zero.
- three public methods:
- addMember(Member mem), which adds a member to the list;
- getEmailAddressForMember(String membersName), which retrieves an email
address given the member's name;
- getHomeAddressForMember(String membersName), which retrieves a home
address given the member's name.
- a helper method findIndex(String name) that will locate the
array index at which the Member's name passed as an argument is stored in the
array.
You may assume the array will always contain the object in question.
Instructions
Write the code for the class GroupRecord to comply with the requirements
above and run the project to test what you have done.