Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

comparator help

 
johnathan smith
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48642
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48642
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought you already had an add method. And we discussed sorting a couple of days ago.
 
Campbell Ritchie
Sheriff
Posts: 48642
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic