• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble trying to increase the scale of my program

 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone,

So I haven't used Java in a couple of semesters so I figured it would be a good idea to work my way through the cattle drive at the JavaRanch site; And I'm having a little trouble expanding the scale of my Say.java program. There are two parts to the assignment:

(1) Write a program that will read in a number from 0 to 99 and spell out that number. The program must also report any values that are out of range.
In other words, I want to type:

java Say 22 and see twenty-two displayed

(2) expand your program from part one to handle numbers as large as 999,999,999,999.

I am having trouble trying to wrap my brain around how I would do this. The only solution in my mind is a whole bunch of strings that would be concatenated together. I was wondering if I could hear alternate solutions.

Here's the code I have so far:


Thanks,
Hunter M.
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have to convert the number 256 to English text you don't need an array of which entry number 256 is "two hundred and fifty-six". That's the point of the "extend this program" exercise. Instead you need to split the number into two parts, then apply the algorithm to each part, then put the two parts back together in the right way. Can you see how to do that with 256?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12083
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also, note that parsing the 999 of the 'billions' is the same as parsing the 999 of the 'millions'.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For 256 you would divide 256 by 100 to get "2" then pass the remainder back into the method
I have already been splitting the number into two parts in the code I posted.

This is what came up with for hundreds



Does this look ok??
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you are on the right track. But have you tested the original code yet? When I run it, it doesn't produce what I would expect for the input "12".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic