Link to home
Start Free TrialLog in
Avatar of tan8888
tan8888

asked on

How to use Java to convert numbers to words.

Hi, I'm trying to write a java code to convert numbers to words, but I somewhat can't find a way to finish it. The application needs two dialog box. The first one ask the user to enter a 4 digit number. The second one shows the result (ex. 123 is equal to one hundred twenty three). Below is what I have so far. I have put the part that I don't how to finish in the notation. Could you guys please give me a hand, or referr me to some similar example? Thank you very much.


import javax.swing.JOptionPane

public class NumberConverterApp {
    public static void main (String[] args){

        String choice="";
        while (!(choice.equalsIgnoreCase("X"))){
              //[how to get and parse input?]
               String[] units = {"one, "two", "three, "four", "five", "six", "seven", "eight", "nine");
               String[] teens{"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
               String[] tens ={"twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};
               String word = "";
               if (num.length == 4){
                     //[how to convert to words?]
               }
               choice = JOptionPane.showInputDialog(numbers + " is equal to \n"
                          + word + "\n Press enter to continue or 'x' to exit.");
          }//end while
          System.exit(0);
       }
   }




ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tan8888
tan8888

ASKER

Thanks a lot for the links. But it would be a lot helpful if I can get a few more tips or examples in order to solve the probelm. Thank you.
they both contain working examples to convert numbers into words, what exactly do you need help with?