• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

arrrrggghhh!

 
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay, i started OOP-3 (SortNames) yesterday and now i am pulling my hair out. however, from reading all the posts on this program i think i have figured out what to do...
i need to create a seperate class that "implements" the interface in question, right? so, i pass an "object" of this new class to the method that "sorts" the last names, right? from what i can tell, my new class needs to return a negative integer, 0 or a 1 to signify if one object is higher or lower than the other one, right?
so far i have managed to write my programs without looking at the posts (or, at least get them to work) but this one is giving me a headache! i am sure there will be a great deal of satisfaction when i finally complete it... and, it is good to see that i am not alone in my frustration.
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup, you got all the right ideas, it's just putting it together in a way that A) works and B) satisfies Marilyn. You'll find that A is a LOT easier
Jason
[This message has been edited by jason adam (edited July 23, 2001).]
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, jason... i feel MUCH better now.
i see in the assignment long that you already have your post for attempt #5 ready and waiting... now i am a little intimidated.
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow, Sun's tutorial site has a very good example of how to implement this interface! i guess i should have looked around some more before i posted my frustration to the Cattle Drive.
i strongly suggest that everyone take a look at it before you start pulling your hair out as i did.
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Greg this one is a tough one. I wish I could explain without giving away the answer.
Carol if you read this how are you doing ???.
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmmm, now i am talking to myself in online forums... it might be time for me to see a doctor about my problem?
i think i have found a way to make this work. i thought i had it earlier, but as i sat in my history class this afternoon i realized that there must be an easier way. so, now i have one class that is about 73 lines long, it uses the 2 different sorting methods and over-rides the "object comparing" method as well.
from some of the posts i read i got the impression that i am supposed to have 2 classes... is that right, or is my way with 1 class okay? i think my program is straight-forward and simple, but i could be wrong! i am really looking forward to the nitpicking on this one.
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember, I haven't been nitpicked on this one...
There has to be at least one class -- SortNames -- to get the program running. There's been some debate about the class that implements the interface. The version I plan to submit for nitpicking has it as a full-fledged independent class. There are plenty of other ways. You saw the example in the Sun tutorial of that interface implemented anonymously and assigned to a static variable. You could also inline the class definition into the method call.
The only version I've thought of that has a single class involves SortNames itself implementing the mystery interface. I thought this was the least appealing of all because of the need to create an instance of SortNames just to pass into the sort method:

method call deleted

I also didn't like what the class definition in this 1-class version seemed to imply -- that part of the point of the class SortNames was to provide one extra way of sorting. (As opposed to the plug-in sort of feel when you implement the interface as a separate class.)
If you came up with a 1-class version that's cleaner than what I described, I'd like to see it after we've both passed the assignment. (Another special forum in the works for discussing solutions to OOP1-4?)
[This message has been edited by Marilyn deQueiroz (edited July 23, 2001).]
 
Ranch Hand
Posts: 111
jQuery Oracle C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Greg, I just thought I would let you know that I had four different versions of this program before I decided which one to send in (three were using just one class and the other had two classes). So there are probably quite a few ways to get a working copy for this assignment. I would submit the most easily readable version and go from there.
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still keep wanting to pull my nested class out as an independent one. From what I read in "Getting in touch with your inner class", static inner classes, or top-level nested classes, are somewhat of a bad thing. I haven't figured a way NOT to make this inner class static and still be able to use everything else, so second independent class might be preferrable.
Btw, is this considered giving too much away?
Jason
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amber Woods:
Hey Greg, I just thought I would let you know that I had four different versions of this program before I decided which one to send in (three were using just one class and the other had two classes). So there are probably quite a few ways to get a working copy for this assignment. I would submit the most easily readable version and go from there.


So woman do program like they buy clothes. They buy about a $1000.00 worth of the stuff and only decide what to wear on the last minute.
and now I'm ducking for cover
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, i had class this morning.
michael, i would really like to see some other solutions to this one as well... my email is in my profile, so when we both finish, send me your address and i will forward the solution.
amber, i am sure i will have a few different ones before it is all over as well... so far the 1 class solution is the most readable, but i am not sure if it satisfies the purpose for the assignment... which is what michael was saying above.
jason, i guess i should read that as well. i have a feeling that my current solution is not the "best" way to go about it.
anyone, from what i read in one of my books last night, "interfaces are "always" saved in a file by themsleves..." is that a true statement (as far as good programming style)?
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Greg, is this how you relax before finals?
Best of luck on Thursday!!
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well,what I think they are saying is if you do this:

That has to be in a file all by itself. But if you implement the interface, like:

That can be in a class file with another non-public class.
Sound right?
[This message has been edited by jason adam (edited July 24, 2001).]
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yea, those two examples go along with what i read last night... however, i did it a 3rd way. though, i am not so sure that i should post that code here because it would give too much away. even if it does not pass the nitpick i will send it to whoever wants to see it because i think it is the simplest way to do this.
pauline, this is not how i relax... rather it is how i try to forget that i have finals tomorrow and thursday! thanks for the luck!
 
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
I think arrrrggghhh just about says all there is to say about SortNames. Except that I have ONE working version of the program and I am still scratching my head trying to figure out why it works. It's not just enough that it works, I have to know WHY. This whole interface concept is very elusive. Even though I am beginning to understand the rules involved in implementing an interface, the why and how escapes me.
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually Carol I saw this article a few seconds ago. Have not read it yet, so ??, but who knows ??
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey carol, i'm glad to know i am not alone here...
i actually understand the "why" because i took an OO course in c++ a couple semesters ago. i love OO programming, and even wrote a poker game that uses about 5 classes.
the sort methods we are using implement a "merge sort" algorithm, so all you have to do is pass the list to the "sort" method, and it does the rest of the work for you... that is the beauty of OO; you can use another method to do your work without having to worry about creating an algorithm of your own.
the other sort method allows you to define the ordering of the sorting... so all you have to do is pass the list and a "sample" of how you want the objects to be ordered (high-to-low, low-to-high) and by which element in the string they should be ordered...
if you do not know about the merge sort; it takes an array, splits it in half and then sorts each half seperately... then it merges the two halves together. in this case the list is 8 names long, so it sorts the first 4, the last 4 and then puts them back together.
put this line in your program inside the method you created, just before the "return()" statement... it will print the sets of "objects" that are being passed in with each reccursion:
System.out.println( one + " " + two );
// where "one" and "two" are the variable names you created.
 
Amber Woods
Ranch Hand
Posts: 111
jQuery Oracle C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Johannes de Jong:
So woman do program like they buy clothes. They buy about a $1000.00 worth of the stuff and only decide what to wear on the last minute.


JDJ, LOL
Exactly!
[This message has been edited by Amber Woods (edited July 25, 2001).]
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent explanation Greg, my biggest hang up starting out with this assignment was wanting to know what was inside sort(). I didn't want to just pass it my list and have it sorted without knowing how. Thanks for shedding some light.
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
glad i could be some help, jason... i have a merge sort function (method) that i wrote in c++ last year if you want to see the actual code so you can see what is going on. of course, i guess i could write it in java now.
i just finished my history final exam... philosophy and calculus tomorrow and then i can spend some time on jsp!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic