wood burning stoves 2.0*
The moose likes Cattle Drive and the fly likes OOP-3 might be the end of me... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "OOP-3 might be the end of me..." Watch "OOP-3 might be the end of me..." New topic
Author

OOP-3 might be the end of me...

Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
I have been racking my brain for a couple of days now on OOP-3 and I have to admit to being more than a little frustrated.
Unfortunately, I think that the questions I have should not be posted here as they are too detailed. Is there anyone who has completed this assignment that would be willing to try and answer some of my questions or at least point me in the right direction? I don't want to bother Marilyn any more than is necessary, so I was hoping for another volunteer.
Thanks,
Joel
mailto:jrc@masi-brac.com


Wait a minute, I'm trying to think of something clever to say...<p>Joel
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1746
    
    2
Drop me a line and I'll see what I can do.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Frustration is understandable with this one, search through the forum here and you'll find plenty of kicking and screaming about how to write this one up (almost as bad as Say). I've sent you my email, though if Mike gets to you first I doubt you'll need any more help, he's a wiz at this
Jason
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Between Michael and Jason you'll be getting quality help with this one. Please include my address when you send your questions - I'd really like to see what's discussed especially when the answers come from those 2 whizzes.
This one is a real brain twister, so all the more satisfying when you get through it. Hang in there.
Pauline
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Maybe Michael can make the questions generic enough to be posted here so everyone can participate. I'd rather stay away from an email list mentality.
[This message has been edited by Marilyn deQueiroz (edited December 06, 2001).]


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
Sorry, Marilyn, I just didn't want to give anything away and be censored for it later
Joel
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1746
    
    2
I haven't forgotten about this. It's just that Jason's kept me tied up in several other forums. Haven't even submitted an assignment lately.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
No problem, Joel. I understand completely.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Originally posted by Michael Matola:
I haven't forgotten about this. It's just that Jason's kept me tied up in several other forums. Haven't even submitted an assignment lately.

Being a Good Samaritan ain't all fun and games, Michael
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1746
    
    2
Originally posted by Marilyn deQueiroz:
No problem, Joel. I understand completely.

You misspelled "Michael."

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932

My first question has to do with Collections.sort() - first of all, since
ArrayList implements the List Interface, and the List Interface extends
Collections, doesn't it stand to reason that ArrayList inherets all of the
Collection methods?

Take a look at the API for this class, specifically that method. There is a certain modifier for that method that causes the method not to be inherited.

I've read all the old posts I
could find regarding this assignment and they indicate that I need to have a
second class. Would this be considered an inner class? Why would I do that
instead of creating a new external class?

I believe this has been implemented both ways. It's your preference. Personally, since this other class is coupled closely with the "main" class, I chose for the first option. Marilyn would be the one to say if one method is preferred over another.

Also, I can't figure out for the life of me which interface I'm supposed to
implement!

Again, look at the API for sort(). You should notice something about that method, and from that you should have your answer
Hope that helps
Jason
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1746
    
    2

My first question has to do with Collections.sort() - first of all, since ArrayList implements the List Interface, and the List Interface extends Collections, doesn't it stand to reason that ArrayList inherets all of the Collection methods?

List doesn't extends Collections; it extends Collection. You're confusing the Collection (no "s") interface and the Collections (with an "s") class.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Doh. Michael's right (a first, huh?), though the concept behind what the modifier of sort() still stands, for future knowledge... hey, can't let Michael be the only hero here.
Jason
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
My first question has to do with Collections.sort() - first of all, since ArrayList implements the List Interface, and the List Interface extends Collections, doesn't it stand to reason that ArrayList inherets all of the Collection methods?

ArrayList implements the List interface which extends the Collection interface. The sort() method is a static method of the Collections class (which is different from the Collection interface).

Look at the Collections.sort() method. You have to make your own comparator object. And in order to do that you will need to implement a special interface.

... I need to have a second class. Would this be considered an inner class? Why would I do that instead of creating a new external class?

Either way is acceptable for this assignment.
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
So when an Interface "extends" something else, that something else is also an Interface? OK, that clears that up...
I think I've found the correct Interface to implement. What I really don't understand still is what good it does me. I still need to create the appropriate method, only now it has to be in a class.
Which brings me back to my "Inner" class question. I was actually looking for clarification that this type of thing would be considered an inner class, but apparently there are multiple ways to create multiple classes inside one .class file. Oy, there is sooooo much to learn!
------------------
I'm a soldier in the NetScape Wars...
Joel
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1746
    
    2
Originally posted by Joel Cochran:
I think I've found the correct Interface to implement. What I really don't understand still is what good it does me.

Do you fully understand how and why sort() worked the first time? If not, reread the API documentation. Look at the Sun tutorial on collections and object ordering.

I still need to create the appropriate method, only now it has to be in a class.

All methods in Java are part of some class or another.
but apparently there are multiple ways to create multiple classes inside one .class file.

There are multiple ways to create multiple classes inside one .java file and/or inside one class definition. Each such class (inner, nested, anonymous, top-level, etc.) will get compiled to its own .class file.
My best personal advice on this (others may disagree) -- forget completely about inner/nested classes for this assignment. If you're not already comfortable with inner/nested classed, it's just a major distraction away from the more interesting things in this assignment. Make your class that implements the interface a top-level, independent class. Even stick it in a separate file if you have to.
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
Originally posted by Michael Matola:

All methods in Java are part of some class or another.

Of course... I meant that this way I have to do it in a seperate class.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Hi Joel, I'm going to take a crack at tying some things together, it sounds like you're really close...
Originally posted by Joel Cochran:
I think I've found the correct Interface to implement. What I really don't understand still is what good it does me.
Here you might have to keep in mind what it is you're looking for. Going backwards and quoting what Marilyn said: "Look at the Collections.sort() method." Not the one you used to sort first names, but one that allows you to sort by some other logic. If you take a close look at this sort method, you'll see that it requires something that you have to provide, as Marilyn said, "You have to make your own comparator object." Does this make sense?
"And in order to do that you will need to implement a special interface."
So to make your object, you'll need a class. That class implements a special interface (you've figured that out already). Then your object is created the usual way, something like this: new ClassThatImplementsASpecialInterface( ). Then you can use it where you need to, in that sort method.

I still need to create the appropriate method, only now it has to be in a class.

That's right. It has to be in the ClassThatImplementsASpecialInterface. That's the deal when you implement an interface - you don't actually have to create the method from scratch, the skeleton is there in the interface - but you have to complete it. (You provide the comparison logic in that method.)

Oy, there is sooooo much to learn!

Ain't that the truth! Hope I haven't given too much away, nor merely mucked up the mire some more.
Pauline
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
So when an Interface "extends" something else, that something else is also an Interface? OK, that clears that up...

An interface can only extend another interface

I still need to create the appropriate method, only now it has to be in a class.

When you use the appropriate method, one of the parameters is an object. You cannot make an object from an interface (you cannot instantiate an interface). You must create a class that implements the interface so you can make an object from it to use in the method.

Which brings me back to my "Inner" class question. I was actually looking for clarification that this type of thing would be considered an inner class, but apparently there are multiple ways to create multiple classes inside one .class file.

I agree with Michael. I recommend that you, Joel, do not use an inner class for this assignment.

There are multiple ways to create multiple classes inside one .java file. The compiler will not allow you to create multiple classes inside one .class file.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
"Only one class per file (excepting inner classes)." -- Style Guide
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OOP-3 might be the end of me...
 
Similar Threads
OOP considered harmful (was: C. Date on UML book)
Does Java support 100% oop's ?
Required Urgently....
Very Urgent...
If you are being "nitpicked" read this