File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes High Scores Table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "High Scores Table" Watch "High Scores Table" New topic

High Scores Table

Daniel McConville

Joined: Jun 04, 2004
Posts: 1
Hi there,

I am currently working on a project for College where I have to take a set of Drivers, Cars, and Managers and using previous results of races calculate a score using a points system.

So far I have just put all the data into arrays and done simple maths on it. Working out my total points for each 'team' has not been a problem. (Yay!)
I now have an array of 5 teams.

team[0] = 33
team[1] = 27
team[2] = 50
team[3] = 33
team[4] = 28

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!

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
This seems to work OK, but there's probably better ways

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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
I agree. Here's the link:
subject: High Scores Table
It's not a secret anymore!