Forums Register Login

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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Drop me a line and I'll see what I can do.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
Sorry, Marilyn, I just didn't want to give anything away and be censored for it later
Joel
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
No problem, Joel. I understand completely.
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
 

Originally posted by Marilyn deQueiroz:
No problem, Joel. I understand completely.


You misspelled "Michael."

+Pie Number of slices to send: Send
 


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
+Pie Number of slices to send: Send
 


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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
"Only one class per file (excepting inner classes)." -- Style Guide
For my next trick, I'll need the help of a tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1041 times.
Similar Threads
OOP considered harmful (was: C. Date on UML book)
Does Java support 100% oop's ?
Very Urgent...
Required Urgently....
If you are being "nitpicked" read this
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:58:04.