beginner help

hi

just a small queery here im having a bit of trouble here

i have a class called Club which contains an arrayList of Players, it also contains add and remove methods for players in the arrayList.

I have a written a class containing a Comparator comparing the batting average of players which is stored in a called class Player.

The code for the comparator is below.

I want to you if it is possible to implement a new method in the club class called add which passes a Player and Comparator hence writing a main program printing information about the players in decreasing order of batting average.

any hints, tips or pseudo code would be much apprecaited.

thanks

publicclass BattingAverageComparatorimplements Comparator<Player>

{

publicint compare(Player player1, Player player2)

{

if(player1.getBattingaverage() < player2.getBattingaverage())

{

return -1;

}

if(player1.getBattingaverage() > player2.getBattingaverage())

{

return 1;

}

else

{

return 0;

}

}

}

[1754 byte] By [] at [2007-11-27 1:32:08]
# 1
After you've used your compartor to sort from highest to lowest simply call the static Collections.reverse method passing the sorted list as a parameter to reverse the order of the list.
paternostroa at 2007-7-12 0:36:02 > top of Java-index,Java Essentials,New To Java...
# 2
If you don't need your list in ascending AND descending order then simply flip the logic of you Comparator around.
floundera at 2007-7-12 0:36:02 > top of Java-index,Java Essentials,New To Java...