I am writing a program that has a membership class. Each Membership object contains details of a person's name, and the month and year in which
they joined the club. All membership details are filled out when a Membership object is created. Then there is a club class that has a field for an array list, a method that returns the current size of the collection and a join method. I am not sure how to get the join method to compile. Anew Membership object should be added to a Club's objects collection via the Club's objects join method, which has the following
signature and description:
/**
* Add a new member to the club's collection of members.
* @param member The member object to be added.
*/
public void join(Membership member)
e following description
Here is my code for the whole class:
public class Club
{
// Define any necessary fields here ...
private ArrayList members;
/**
* Constructor for objects of class Club
*/
public Club()
{
// Initialise any fields here ...
members = new ArrayList();
}
/**
* Add a new member to the club's list of members.
* @param member The member object to be added.
*/
public void join(Membership member)
{
members.add(Membership.member);
}
/**
* @return The number of members (Membership objects) in
* the club.
*/
public int numberOfMembers()
{
return members.size();
}
}
Code tags added -Narue