This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have to make a program that will take fouyr strings, received through JOptionPane, and print to screen these 4 strings in both ascending and descending alphabetic sequence. I'm sure it's simple, but it's giving me trouble. Ideally what I'd like to do is read in the strings, store them, then pass those 4 strings as arguments to construct a "word" object. Then call methods on this object which will fulfill the requirements.
It's these methods that are giving me trouble. I DON'T want to use an array at all, so havings aid that, I gather I'd use the method string1.compareToIgnoreCase(string2), which makes perfect sense. However, how do I make this work properly without simply hardcoding in a multitude of if statements that address every possible permutation? Though that would work, I can't think of anything uglier. ;-)
Any help here would be greatly appreciated. I haven't posted any code, as all I have is literally the method headers with no implementation code within them! Thanks in advance!
I've been trying to change the world for years, but they just won't give me the source code.
Originally posted by fred rosenberger: I'm not saying you HAVE to use an array, or even that you SHOULD use one - i just don't understand your apparent predjudice against them...
Because the homework assignment said don't use arrays?
If you know they're Strings and you know there's exactly four of them, a String sounds like the right way to store the data. If there were different classes, an unknown or large number of them, Collections might be good. You can either use an unsorted Collection, like ArrayList, then sort it using methods on Collections, or use a sorted Collection, like TreeSet. Although it might be tricky to sort in both directions, with TreeSet.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
[ November 15, 2004: Message edited by: Mike Gershman ]
SCJP 1.4, SCWCD in process
Joined: Jun 24, 2002
I like arrays as much as the next guy, the reason I don't want to use them in this case is that I'm doing the exercises from a java book, and this question appear at the end of chapter 4, BEFORE arrays and vectors and lists are ever introduced, which implied to me that one should use another method (pardon the pun) to execute the task. I'm assuming that the reason is to give someone a really good appreciation of arrays when they're brought into play, which is in chapter 5, much to my consternation. ;-)