Question: using java, Sometimes numbers are converted to words, like in a wedding invitation. So 2 3 becomes twenty three. Write a method digitToWord ( )

using java, Sometimes numbers are converted to words, like in a wedding invitation. So 23 becomes "twenty three". Write a method digitToWord() that takes a single digit number from 0-9 and returns that number's word: 0 is zero, 1 is one, 2 is two, etc (if the number is outside 0-9, return "error"). Write another method tensDigitToWord() that takes a single digit number from 2-9, and returns that number's word when it appears in the tens digit: 2 is twenty, 3 is thirty, etc. If the number is outside 2-9, return "error". Finally, write a method twoDigitNumToWords() that takes a two-digit number from 20-99 and returns that number in words. Your main program should get a user's integer, call twoDigitNumToWords(), and output the resulting string. If the input is 23, the output should be "twenty three".
Do not do any error checking of the input. Note that your program does not support all numbers. 0-19 will yield error output, for example.
HINTS:
Write digitToWord() first, and test the method (have your main call that method directly)-- you won't pass any of the tests, but you should still start that way. Next, write tensDigitToWord() and test it by itself also. Finally, write twoDigitNumToWords()(calling your first two methods) and test the entire program.
Your twoDigitNumToWords() method should pass the ten's digit to tensDigitToWord(). To get the tens digit, divide the number by 10.
Your twoDigitNumToWords() method should pass the one's digit to digitToWord(). To get the ones digit, mod the number by 10(num %10).
You can concatenate the strings returned by those two methods using the + operator. Ex: "hello" +""+ "there" yields one string "hello there".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!