• Post Reply Bookmark Topic Watch Topic
  • New Topic

Comparing integers  RSS feed

 
Sally Curtis
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to compare a 'rank' score of speech competitors in my program
the following code alphabatises the names of the people


is there any way i could assign a new array RankGroup to debateGroup and and make a copy of this for loop and use it to rank the students by there rank score value? and i know that compareto. only works with string....is there something that compares ints....if anyone has any ideas on i how would rank the scores by least pt value being first place...pls help
thanks
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's something to play around with
 
Sally Curtis
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the code, but im a beginner java student and im bit confused with the code. can u pls explain the code ?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first part just deals with creating a few 'Students'.
Then they're sorted by 'mark' (or in your terminology, rank)
Then the output (should be) in sorted order.
The java API will do a better job than I can about how Collections.sort
and Comparator work.
 
roy joseph
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bubble sort would do the trick.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming debateGroup is an array of objects that contain names and grades, and that you have the appropriate methods, you could use getScore() instead of getLastName()?
your while condition would change to something like
while(ts > 0 && debateGroup[ts-1].getScore() < debateGroup[ts].getScore())
 
sever oon
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recommend you read up on the Java Collections API, particularly the sorting mechanisms based on Comparator. It sounds to me like all you have to do is implement a couple of different subclasses for Comparator, and you can use the Java Collections API to do all your sorting for you.
If this isn't enough direction and you need a few more pointers getting started on this, let me know, but read the javadocs first on the API and classes mentioned above.
sev
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!