• 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 ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

OOP-3 Sort Names

 
Ranch Hand
Posts: 111
jQuery Oracle C++
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wondering what how to implement an interface means in the directions for this assignment?
This is what I have done so far for this assignment. I read the list of names into an ArrayList, Then used Collections to sort the list, Then I printed the list. It seems to work but my program is about half the size of the solution so I am guessing that I am missing something here.
Anyone with suggestions?
Amber Woods
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you got the first part to work fine (the easy part)...but you make no mention of the last-name sort. Have you done that part yet? That is where you need to implement a particular interface.
------------------
  • Ryan Burgdorfer
  • Java Acolyte
 
Amber Woods
Ranch Hand
Posts: 111
jQuery Oracle C++
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tested it and it seems to work for the last names as well. But now that I think about it maybe I haven't tested it thoroughly enough! I will test some more but I still don't know what interface we are speaking of
Hopefully I can figure it out!!
Amber
 
Amber Woods
Ranch Hand
Posts: 111
jQuery Oracle C++
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tested some more and this is the result
infile.txt =
Adam Baum
Justin Case
Bill Joy
James Gosling
Walter Cronkite
Joe Montana
James Abner
Abraham Lincoln
Connie Chung
Adam Apple
Walter Andy
Bill Keifer
Joe Montaab
Adam Baul
ArrayList printed as result of Sort:
Abraham Lincoln
Adam Apple
Adam Baul
Adam Baum
Bill Joy
Bill Keifer
Connie Chung
James Abner
James Gosling
Joe Montaab
Joe Montana
Justin Case
Walter Andy
Walter Cronkite
I thought that was what the program was supposed to do??
Amber
 
ryan burgdorfer
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is what the first requirement says it should do...but the second requirement says that it also needs to sort/output the list by LAST names. To do that, you need to make a new class that implements a certain interface...if you look around the API, on the pages for the classes used for the first requirement, yuo will find a reference to the interface you need to use to do the second "last name" sort.
------------------
  • Ryan Burgdorfer
  • Java Acolyte
 
ryan burgdorfer
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, where are you getting all the extra names from? The list given for the assignment has 8 names...
First req.: Sort and output the list by FIRST names.
Second req.: Sort and output the list by LAST names.
Thus your program will output 2 lists of 8 names each, the first sorted by first name and the second sorted by last name.
------------------
  • Ryan Burgdorfer
  • Java Acolyte
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My instinct with this would be to substring each of the Strings but that would involve making a copy wouldn't it?
What am I missing here?
-m
 
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make substrings.� If you read in string as "Justin Case", don't store "Case Justin"
 
Amber Woods
Ranch Hand
Posts: 111
jQuery Oracle C++
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ryan
I did not understand the directions to mean print two lists, thanks for the clarification. I did implement the interface and it works but I am not sure if the way I implemented it is correct. Guess I will have to wait till I can send it in to be nitpicked.
I put extra names in my list just as an extra test. I knew it was sorting the first names correctly but I wasn't sure if it sorted using the whole string (firstname space lastname) or just the first name.
Thanks again
Amber Woods
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!