• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

comparator help

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought you already had an add method. And we discussed sorting a couple of days ago.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic