The object of this activity was to extend the Member class by a class CommitteeMember, and override the toString method defined by Member.
The GroupRecord class begun in Activity 3.5 is included in this project and two methods have been added to it, giving it slightly more functionality than before:
Here follows the completed class CommitteeMember:
public class CommitteeMember extends Member
{
private String position;
public CommitteeMember(String nam, String ema, String adr, String pos)
{
super(nam, ema, adr);
position = pos;
}
public String getPosition()
{
return position;
}
/* We can make use of the parent toString method.
This technique works even if there are no public getter methods
in the parent for any variables we wish to access,
but the parent toString method may not return exactly what we want */
public String toString()
{
String text;
text = super.toString(); //use the parent toString method
text = text + "(" + position + ")"; //add locally defined information
return text;
}
/* An alternative solution illustrated below is to use available parent
getter methods such as getName. This gives extra flexibility in this method.
We have chosen to use the same form of output as the parent class.
We add the 'position' information defined in this class
*/
/*
public String toString()
{
return getName() + ", email address " + getEmailAddress()
+ ", home address " + getHomeAddress() + "(" + getPosition() + ")";
}
*/
}
Think about the following points: