• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SortNames woes...

 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • 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!
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last name sort solution still eludes me.


Sun tutorial on Object Ordering might give you some ideas.
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcus,
Check this thread in beginners for an example.
 
paul wheaton
Trailboss
Pie
Posts: 21735
Firefox Browser IntelliJ IDE Java
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
Carol Murphy
village idiot
Bartender
Posts: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a link to one of my posts from back when I was working through this assignment: http://www.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
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic