File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Trouble trying to increase the scale of my program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble trying to increase the scale of my program" Watch "Trouble trying to increase the scale of my program" New topic
Author

Trouble trying to increase the scale of my program

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

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.


"If the facts don't fit the theory, get new facts" --Albert Einstein
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Oct 02, 2003
Posts: 11139
    
  16

also, note that parsing the 999 of the 'billions' is the same as parsing the 999 of the 'millions'.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble trying to increase the scale of my program
 
Similar Threads
Print Statement help
Project Euler #17
can anyone solve this ?
Assignment 1.4 (Say)
converting amount to words