instead of doing an if...else thing, perhaps a "switch" will be better?
private String getNumber( int i )
{
switch ( i )
{
case 0 : return "zero";
case 1 : return "one";
.
.
.
}
just for some reason i find doing more than one if with an else rather tacky looking... but that's just my opinion.
what you could do to test whether you are on the right track with getting the numbers separated, is when you call getHundreds() or whatever, you can print it to the screen:
number = 1234
thousands = 1
hundreds = 2
etc.
because "value % 1000 / 10" would return 23.
do you have to convert "1234" to "one two three four" or "one thousand two hundred and thirty four"?
Easter Bunny
Junior Poster in Training
57 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
Easter Bunny
Junior Poster in Training
57 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
ok, you can worry about the caps when the program works. for now see if you can write out "one two three four".
when you have that, work at get the last two digits to thiry four. that's when you'll have to use the tensAndOnesToString() method and test the tens and ones individually.
you can test the first number and see whether you have to say thirty-something, forty-something, etc. change the program so that your output will be "one two thirty".
work in little steps. don't try to rewrite unix and make it work first time. :)
Easter Bunny
Junior Poster in Training
57 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
all you need to do to test the methods, is to ask the user to give you a number, then you write that number out in words, but without saying thousands or hundreds. just tell the user he entered "one two three four".
the problem you have with getting the hundreds, can easily be solved by saying:
int i = value / 100 % 10;
value = 1234
then you divide it by 100 and now
value = 12
then you "mod" it by 10 (divide by ten and then it gives you the remainder) and now
value = 2
Easter Bunny
Junior Poster in Training
57 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
yes, if you fix the getHundreds method to what i posted, then you will get the right number.
Easter Bunny
Junior Poster in Training
57 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1