Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

High Scores Table

 
Daniel McConville
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

-Daniel
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems to work OK, but there's probably better ways

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic