Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

High Scores Table

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!

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

(instanceof Sidekick)
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!
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic