Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes comparator help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "comparator help" Watch "comparator help" New topic
Author

comparator help

johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
hi
i have the following comparator class written to compare to players in a team by batting averages

i would now like to write a method called add to my Club class which passes a Player and a comparator hense writing a main program which which prints information about each player in the club in decreasing order of batting average?

Club class contains an array list and also add and remove player methods

how would this be achieved?
any hints or pseudo code would be much apprecaited
thanks

the comparator code
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
It would be better form only to have one return in the compare() method, but apart from that I think it ought to work. And you can change the 2nd if to an else-if
[ April 19, 2007: Message edited by: Campbell Ritchie ]
johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
thanks for the help

but i now want to write an add method to my club class which passes a Player and a Comparator and prints out the player information in decending order of batting average

how do i go about doing this?
any help is much appreciated

thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
I thought you already had an add method. And we discussed sorting a couple of days ago.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
I think you will find it much easier to add and sort separately. Apart from the fact that it is a bad idea to have a method which carries out two unrelated tasks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: comparator help