Results 1 to 7 of 7
Thread: help with an assignment!
- 10-24-2010, 09:35 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
help with an assignment!
I am given a comparator that sorts the rank of a list of military soldiers in alphabetical order, the code is the following
Java Code:public class SoldierRank implements Comparator<Soldier>{ public int compare(Soldier left, Soldier right){ return left.getRank().compareTo(right.getRank()); } }
But i am completely clueless right now, could somebody help me out? Thanks :)
-
- 10-24-2010, 09:46 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
-
- 10-24-2010, 11:06 PM #5
I would probably just make the ranks numbers: 1,2,3... all corresponding to a certain rank. That way you can print them out in order very easily.
Sincerely, Joshua Green
Please REP if I help :)
-
But this may make it somewhat difficult to debug later. Best to use enums which were added to the language for just this sort of thing. They already implement the Comparable interface and rank things based on the order of declaration. The toString can allow you to output the results ever so nicely.
- 10-24-2010, 11:32 PM #7
Similar Threads
-
Need help with a assignment
By helpMe.Java in forum New To JavaReplies: 7Last Post: 06-06-2010, 04:49 PM -
need help! assignment due by tmr!
By keycoffee in forum New To JavaReplies: 3Last Post: 02-10-2010, 05:45 PM -
Can somebody help me in my assignment
By coolstruxx in forum NetBeansReplies: 0Last Post: 03-24-2009, 01:27 AM -
I am looking for help with an assignment
By nanoo51969 in forum New To JavaReplies: 1Last Post: 03-23-2009, 09:41 PM -
First GUI Assignment
By ljk8950 in forum New To JavaReplies: 1Last Post: 07-31-2008, 07:29 AM
Bookmarks