I am trying to write a method for a club that holds information on the members. The method is when a month is entered it will tell you how many members joined in that month. My code is like this:
import java.util.ArrayList; /** * Store details of club memberships. * * @author (your name) * @version (a version number or a date) */ public class Club { // Define any necessary fields here ... private ArrayList<Membership> members; /** * Constructor for objects of class Club */ public Club() { // Initialise any fields here ... members = new ArrayList<Membership>(); } /** * 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(member); } /** * @return The number of members (Membership objects) in * the club. */ public int numberOfMembers() { return members.size(); } /** Determine the number of members who * joined in a given month * @param month The month we are interested in * @return The number of members joining in month. */ public int joinedInMonth(int month) { if(month < 1 || month > 12) { System.out.println("error"); return 0; } else{ } } } }
This class is linked to a membership class
I just don't know how I can make it count the number of members that have joined in the certain month
I know that I will need a loop but I don't know how I would do it