CODE
/**
* Remove from the club's collection all members who
* joined in the given month, and return them stored
* in a sparate collection object.
* @param month The month of the membership.
* @param year The year of the membership.
* @return The number of members.
*/
public ArrayList<Membership> purge(int month, int year)
{
if(month >= 1 && month <= 12)
{
Iterator it = members.iterator();
ArrayList<Membership> purged;
purged = new ArrayList();
int counter = 0;
while(it.hasNext())
{
Membership member = (Membership) it.next();
if((member.getMonth() == month) && (member.getYear() == year))
{
purged.add(member);
members.remove(counter);
}
counter++;
}
return purged;
}
System.out.println("Invalid month of "+month);
return null;
}
* Remove from the club's collection all members who
* joined in the given month, and return them stored
* in a sparate collection object.
* @param month The month of the membership.
* @param year The year of the membership.
* @return The number of members.
*/
public ArrayList<Membership> purge(int month, int year)
{
if(month >= 1 && month <= 12)
{
Iterator it = members.iterator();
ArrayList<Membership> purged;
purged = new ArrayList();
int counter = 0;
while(it.hasNext())
{
Membership member = (Membership) it.next();
if((member.getMonth() == month) && (member.getYear() == year))
{
purged.add(member);
members.remove(counter);
}
counter++;
}
return purged;
}
System.out.println("Invalid month of "+month);
return null;
}
This is what I've got so far. there is bascially two classes involved here:
Membership and Club
A club holds memberships
Membership holds details of name, join month, join year.
The method is suppose to take a month and year then look through the clubs membership collection and return the ones at match as an array of Membership. THe ones that match also need to be removed from the clubs collection.
I think whats happening while I'm observing in the debugger is when It loops through the ones that match and start removing it messes up the iterator so no more loops happen and only 1 match is return. Any ideas on how to go about this? I'm still fairly new to java
edit:
Ok I looked iterator method remove() ; ; that did the job. Sorry guys for posting this up it was my own fault. I read this method first round but the description didnt sound right. I thought it was gonna remove the whole iterator.
Probably a good idea to delete this Mod since I dont think its gonna be any valuable.


