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 becomes "twenty three". Write a method digitToWord that takes a single digit number from and returns that number's word: is zero, is one, is two, etc if the number is outside return "error" Write another method tensDigitToWord that takes a single digit number from and returns that number's word when it appears in the tens digit: is twenty, is thirty, etc. If the number is outside return "error". Finally, write a method twoDigitNumToWords that takes a twodigit number from 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 the output should be "twenty three".
Do not do any error checking of the input. Note that your program does not support all numbers. 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 twoDigitNumToWordscalling 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
Your twoDigitNumToWords method should pass the one's digit to digitToWord To get the ones digit, mod the number by num
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
