This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes Hint on OOP-3 Please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Hint on OOP-3 Please" Watch "Hint on OOP-3 Please" New topic
Author

Hint on OOP-3 Please

Daniel Loranz
Ranch Hand

Joined: Jun 17, 2008
Posts: 41
Sorting by first name was pretty straightforward.

I'm stuck on sorting by last name while staying within the parameters of the assignment. I could build a new list with the elements being lastName, firstName, but I think this violates the assignment requirements.

Does Comparator help me in this assignment?

Thanks.
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
Hi Daniel.

This assignment gave me fits. I'd highly recommend searching for all topics titled sortnames in the cattledrive forum. Read through a few, the information found there is invaluable.

This thread was pretty good as far as dropping a key hint in the right direction, and there are several others which now (looking back on the problem and knowing what needs to be done) almost give you the answer. Also I did a google search for "how to sort an arraylist alphabetically" after looking through the search results on JavaRanch and studying Collections on the Java tutorial through Sun, and the answer almost jumped out and bit me.

Just remember that you'll need to implement an interface, where one of the implemented methods does some comparing. You need to tell it exactly where to compare.


The very existence of flamethrowers proves that at some time, some where, some place, someone once said to themselves "I'd really like to set those people on fire over there, but I just can't get close enough".
Daniel Loranz
Ranch Hand

Joined: Jun 17, 2008
Posts: 41
Thanks. The thread looks very helpful.
Daniel Loranz
Ranch Hand

Joined: Jun 17, 2008
Posts: 41


Whew! Got SortNames to work - and I feel GREAT! Wow, what an awesome example of the usefulness of an object approach. It took me quite awhile to work out how to properly fit my own classes into the larger java picture, but when I finally got the syntax correct, the amount of coding on my part was quite minimal. Very cool!

Very nice!
 
jQuery in Action, 2nd edition
 
subject: Hint on OOP-3 Please
 
Similar Threads
Top N Analysis
B&S using a sorted column table to display the records? How many of you have done this?
OOP-3 Sorting
OOP 3: SortNames
SortNames