aspose file tools*
The moose likes Cattle Drive and the fly likes  Assignment Java-4a (Say) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark " Assignment Java-4a (Say)" Watch " Assignment Java-4a (Say)" New topic
Author

Assignment Java-4a (Say)

Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
Right, now.....
I've done assignment 4a, but after marking, two comments i've been given are:-
"Notice how a lot of array elements share words that are the same?"
&
"How about using more than one array? Then you can use combinations of values from the arrays (when necessary) to print out what you want"

So in other words, I can trim my code down (what a pain I can't post it!). I can't see how I can share parts of words.
i.e.
If I type 23 - the program outpurs twenty-three
and
If I type 24 - the program outpurs twenty-four

I can share the 'twenty' bit, right?
But how??


John Bonham was stronger, but Keith Moon was faster.
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
ahhh, 4a-Say... what fond memories.
the hint about using "more than one array" is very good... i assume you are reading the input (23) and then printing a string (twenty-three) accordingly. maybe you could have another method to handle values in the 2nd array.


what?
juliane gross
Ranch Hand

Joined: May 30, 2002
Posts: 161
right, Steve, you share the "twenty" part (for example). Fill one array with numbers that behave similar, and another array with the other similar behaving numbers. Add the "-" seperately in case the input number is concatenated.
Hope you have fun cracking this assignment as I had!
Juliane
Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
Originally posted by juliane gross:
right, Steve, you share the "twenty" part (for example). Fill one array with numbers that behave similar, and another array with the other similar behaving numbers. Add the "-" seperately in case the input number is concatenated.
Hope you have fun cracking this assignment as I had!
Juliane


Surely that therefore means I have to search the inputted string, to check for the number "2", and do a tets to see if there is another charcater after that?? Also, when I search the inputted strings, I have to find out what the values of them are??
Am i going on the right lines - needing to use string seraches and such like??
It's a freezing cold, dank and dark Friday evening in London, and I feel as though this assignment is out to get me.
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
think about it this way:
when you visually read a number, your brain first looks to see how many digits there are in the number and then processes each digit according to the value associated with its position in the number. of course, you process from largest to smallest.
so how does that convert to a java program? look at the number to see how many places there are and then process each digit according to its position in the string. in 4a-Say, you are only dealing with 0-99... so you will only have 2 digits to worry about.
also, think about how you can use math to see if a number is greater than 9...
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
You can do it with strings, or you can convert the string to an int and separate the tens and ones with math.


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

Joined: Sep 23, 2002
Posts: 126
Originally posted by Marilyn de Queiroz:
You can do it with strings, or you can convert the string to an int and separate the tens and ones with math.

So really, there's a lot more to it than what the question asks??
David Mason
Ranch Hand

Joined: Jan 21, 2002
Posts: 56

Hi Steve.
I think the example in the assignment is quite useful ...
"I want to type .. 22 .. and see twenty-two", especially when when you combine it with Marilyn's suggestion that you "separate the tens and ones with math." and the hint about using "more than one array"
It's two two's, right ? Or is one two more significant (maths-wise) than t'other ?
BTW how would you go about converting 22 to hex ?
[ December 20, 2002: Message edited by: David Mason ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
Converting to hex is not required to complete this assignment.
[ December 21, 2002: Message edited by: Marilyn de Queiroz ]
David Mason
Ranch Hand

Joined: Jan 21, 2002
Posts: 56

I use conversion to hex as an example of a thought process. eg it's 22 in base 10 and 16 in base 16. ie What do you need to do, to do such a conversion?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
David, it's a great analogue, but I guess Marilyn wants Steve to remain focused. "Zen and the art of Nitpickin'" sort of thing. Sometimes when one is stuck on a problem, one is like an astronaut floating around in space, you need exactly the right nudge to get where you have to go, but if too hard or in the wrong direction, then it's very hard to get back on track.
Beam me up Scotty...
-Barry
(4b or not 4b THAT is the question.)


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1749
    
    2
Originally posted by Steve Jensen:

So really, there's a lot more to it than what the question asks??

There have been times when my response to a nitpick has been to change a single character in my program.
There have been times when my response to a nitpick has been to rethink my entire approach to a problem and essentially rewrite the program (or section of a program).
Most times things fall somewhere in between.
*****
There are numerous lessons to be learned from the Say assignments. One is to find recurring patterns in a problem and to take advantage of those patterns when building a solution. Another is to learn not to encode a single piece of information in more than one place (the DRY princple -- Don't Repeat Yourself).
"20" -> "twenty"
"21" -> "twenty-one"
"22" -> "twenty-two"
...
"30" -> "thirty"
"31" -> "thirty-one"
and so on. If your program is somehow capturing in more than one place the fact that "20" translates to "twenty," or that "30" translates to "thirty," then there're definitely ways to improve it.
[ December 21, 2002: Message edited by: Michael Matola ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assignment Java-4a (Say)