• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

SortNames woes...

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Except for the first assignment when I was cutting my teeth and SayB, I've really enjoyed the challenge of the Cattle Drive. Now I'm really stumped!

As you can tell, I'm on the SortNames assignment. I'm befuddled (read.. I really don't get it) about the extravagence of using an interface in this exercise.

To avoid repeating a bad idea, I will not indicate what solution I suggested to Marilyn in my email to her. She refered me to this discussion forum.

I got the exercise to work, sorting by first name. I used ArrayList and Collections to get to the output (First / Last)I needed. The last name sort solution still eludes me.

I did research in this forum to see if I could glean any hints on what to do, but it was all to no avail!

I dont't understand what advantage an interface has, and, once I have the interface, what benifit it will bring. Please help!
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The last name sort solution still eludes me.



Sun tutorial on Object Ordering might give you some ideas.
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont't understand what advantage an interface has, and, once I have the interface, what benifit it will bring. Please help!

It's been a while since I've thought about the SortNames assignment, but maybe I can help at a real general level...

An interface usually gives you the advantage of letting you add some functionality to your class that it might not otherwise have. In this case, you need to sort by last names. Before you can sort a bunch of names, though, you need to be able to compare those names to eachother. That's where a certain interface might come in handy.

If that's altogether too vague, please say so. I think I remember some helpful conversations on this one, I'll try to dig them up...

Hang in there!
[ March 15, 2005: Message edited by: Pauline McNamara ]
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's one favorite on SortNames. There's a bunch of good ones out there - a quick search using 'sort names' got 'em.

Are you having fun yet?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[PM]: An interface usually gives you the advantage of letting you add some functionality to your class that it might not otherwise have.

You might add the functionality to an existing class, or you might just create a brand new class that implements the interface. Interfaces are very flexible in this respect.
 
author & internet detective
Posts: 41578
881
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marcus,
Check this thread in beginners for an example.
 
Trailboss
Posts: 23644
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a ditty I wrote a few years ago: http://www.javaranch.com/CodeBarn/shapes.jsp
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interfaces allows you to code a class that won't know or doesn't care what the actual implementation class is.

So you have a

Person interface with a name and one method getName()

Now you have a Pauline, Mark, Paul, and Jim class, each of which implement the Person interface.

So if I have a class called Invitation with a method called sendInvite(Person p)

this method can call p.getName() without caring whether it is Paul, Pauline, Mark, or Jim.

Interfaces are very powerful and help open the big world of Design Patterns.

Mark
 
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a link to one of my posts from back when I was working through this assignment: https://coderanch.com/t/4169/Cattle-Drive/Sorting-it-out
You are not alone!
[ March 18, 2005: Message edited by: Carol Murphy ]
 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,

Now that I have my machine running again (BIOS upgrade), I'll take a look at it.

Seems to me that others have needed help too! I"m so glad. Sometimes I feel so dumb!
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic