Numbers to Words
Note: Feel free to work with a partner on this.
Getting Started
Look a the code in the Code directory off the class web page named
NumToWords.java.
It is a partial implementation of a
NumToWords
class that might be used to write the amount of a check in words as
well as numerically.
Enter it into Eclipse. It should run, but not at all correctly. You need to
to start by implementing the method
nums().
Use a series of if/else or a switch statement to help implement it.
When you implement that correctly, the first part of the test should work
printing out the words "zero" thru "nine" on the console.
Dealing With Two-digit Integers
When you are done with single digit case, you need to tackle two digits
by writing
twoDigit().
Your logic should break the two digit number into two separate digits
and then apply
nums()
to each digit. For example, if passed 36, it should return the string
"three six" and if passed 7, it should return the string "zero seven".
Hint: What is 36 % 10 ? What is 36 / 10 ?
When this is complete, your
main()
will test your method with 10 randomly
generated two-digit numbers. They should be different for each execution.
Extra Credit
Tackle the general two-digit case and do it right. 37 should produce
"thirty seven", not "three seven", 12 should produce "twelve" and 8 should
produce "eight", not "zero eight".
For this you will need to add several methods. One should handle the
digits 11 thru 19. Another should handle the multiples of 10: 10, 20, 30 ...
Then, of course, you need a more sophisticated
TwoDigit routine. To avoid confusion with the required part, call this
method
wordsTo99().
You'll also have to extend the tests in main to convince the graders that
your code is working correctly.
Submit for Grading
When all is done, turn in your work using the submit feature of Eclipse under
the name
NumtToWords
Include a README file stating who worked on this (who was your partner, if
any) and who helped you with it. Also estimate you much time you spent on it.