I am writing a program that is a basic cricket club roster, and have been asked to "Implement a new Constructor for the Club class that passes a Comparator."
I have a class called "BattingAverageSorter" that does the following:
import java.util.Comparator;
public class BattingAverageSorter implements Comparator<Player>{
public int compare(Player p1, Player p2){
if(p1.getBattingAv() < p2.getBattingAv())
{
return -1;
}
else if(p1.getBattingAv() > p2.getBattingAv())
{
return 1;
}
else
{
return 0;
}
}
}
Which works with: Collections.sort(playerList, new BattingAverageSorter()); fine.
I don't quite understand what I am being asked. I have googled around trying to read up around it and even looked in the books/notes I have and still can't find anything.
Tried to do:
private List<Player> playerList = new ArrayList<Player>(new BattingAverageSorter());
But Eclipse gives me an error. Is there any where I can be pointed toward to understand what I am being asked?
This post has been edited by mrfinch: 09 April 2009 - 10:01 AM

New Topic/Question
Reply




MultiQuote





|