• 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

Assignment Java-4a (Say)

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Steve Jensen
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do it with strings, or you can convert the string to an int and separate the tens and ones with math.
 
Steve Jensen
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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??
 
Ranch Hand
Posts: 56
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Converting to hex is not required to complete this assignment.
[ December 21, 2002: Message edited by: Marilyn de Queiroz ]
 
David Mason
Ranch Hand
Posts: 56
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic