Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Text to Digit Converter: Create a javascript application for the following task.

ID: 3570605 • Letter: T

Question

Text to Digit Converter:

Create a javascript application for the following task. A digits to text converter and/or text to digits converter. Use your creativity to produce a good product. The interface contains (a) A good looking page with a rectangular border, background color, centered text, stylish fonts, any other style features, labels , proportional fonts etc., (b) One text box for inputting numbers ( Currency) and another text area to display converted text, two radio buttons to choose text to digit or digit to text conversion and a

Explanation / Answer

import java.lang.*;

import java.util.*;

import java.io.*;

class NumberToWords

{

      static public boolean HelperConvertNumberToText(int num, String[] result)

      {

          String [] strones = {

            "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",

            "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",

            "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen",

          };

       

          String [] strtens = {

              "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty",

              "Seventy", "Eighty", "Ninety", "Hundred"

          };

          result[0] = "";

          int single, tens, hundreds;

       

          if(num > 1000)

              return false;

       

          hundreds = num / 100;

          num = num - hundreds * 100;

          if( num < 20)

          {

              tens = 0; // special case

              single = num;

          }

          else

          {

              tens = num / 10;

              num = num - tens * 10;

              single = num;

          }

         

          if(hundreds > 0)

          {

             result[0] += strones[hundreds-1];

             result[0] += " Hundred ";

          }

          if(tens > 0)

        {

             result[0] += strtens[tens - 1];

             result[0] += " ";

          }

          if(single > 0)

          {

             result[0] += strones[single - 1];

             result[0] += " ";

          }

          return true;

     }

      static public boolean ConvertNumberToText(int num, String[] result)

      {

          String tempString[] = new String[1];

          tempString[0] = "";

          int thousands;

          int temp;

          result[0] = "";

          if(num < 0 || num > 100000)

          {

              System.out.println(num + " Not Supported");

              return false;

          }

       

          if( num == 0)

          {

             System.out.println(num + " Zero");

             return false;

          }

               

          if(num < 1000)

          {  

              HelperConvertNumberToText(num, tempString);

              result[0] += tempString[0];

          }

          else

          {

              thousands = num / 1000;

              temp = num - thousands * 1000;

              HelperConvertNumberToText(thousands, tempString);

              result[0] += tempString[0];

              result[0] += "Thousand ";             

              HelperConvertNumberToText(temp, tempString);

              result[0] += tempString[0];

          }

          return true;

      }

      public static void main(String[] args)

      {

          String [] result = new String[1];

          result[0] = "";

          int i, num;

          int [] arrNum =

          {

            -1, 0, 5, 10, 15, 19, 20, 21, 25, 33, 49, 50, 72,

            99, 100, 101, 117, 199, 200, 214, 517, 589, 999,

            1000, 1010, 1018, 1200, 9890, 10119, 13535, 57019,

            99999, 100000, 100001

          };

          for (i = 0; i < arrNum.length; i++)

          {

              num = arrNum[i];

              if( ConvertNumberToText(num, result) == true)

                 System.out.println(num + " " + result[0]);

          }

      }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote