I need to sort this data into a 'Winners Prediction' based on scores. If I use Arrays.sort it just sorts the array into decending order and then I dont know which team got what orginal score.
I need to find some way of sorting the data from highest to lowest and knowing which team has placed, 1st 2nd 3rd 4th 5th.
Can anyone give me any tips or advice? Thankyou!
Joined: Jun 09, 2003
This seems to work OK, but there's probably better ways
Joined: Jan 29, 2003
I think you'll want something more than a simple array of scores. Once you have that array of scores sorted, how do you know which score goes with which team?
Would you be comfortable making a Team class? It might hold some team data for you:
You could make an array (or some collection, hint hint) of Team objects and sort those by score. Then you could go through the sorted array and print name & score for each Team object.
If you want to go that direction, look into the JavaDoc APIs for Set to hold your objects. Is there a flavor of Set that would do the sorting for you? And see the Comparable interface to help you sort them. Feel free to take a stab at that, see how far you get, post some code for comment.
Hope that helps. Have fun!
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi