Description:The program basically lets the user input numbers from 0 - 99,999.9 which the program will convert the inputed number to it's equivalent words.
example
Input number: 3
World Equivalent: Three dollars
I have established to convert a ones digit.
public class NumberConvert
{
/*
*Function name: main
*Description: This is where the main calls for a method(s). And from there it process
* the codes and prints them.
*Arguments: String args[]
*Return Type: none
*Known Bugs:
*/
public static void main(String args[])
throws Exception
{
System.out.println("Welcome to Money Conversion!" + "\n");
String strContinue;
String strInputs = "";
do
{
Double dInput = ReaderData.getDoubleInput("Input number: ");
String sInput = Double.toString(dInput);
String WordEquivalent = "";
for(int iCtr = 3; iCtr <= sInput.length(); iCtr++)
{
if(iCtr == 3)
{
// OOP
NumberConvert obj = new NumberConvert();
String Ones = sInput.substring((sInput.length() - iCtr), (sInput.length() - (iCtr - 1)));
Ones = obj.getOnes(Ones);
WordEquivalent = WordEquivalent + Ones;
}
}
System.out.println("\n" + "Word Equivalent: " + WordEquivalent + " Dollars" + "\n");
if(strInputs.equals(""))
{
strInputs = WordEquivalent;
}
else
{
strInputs = strInputs + " , " + WordEquivalent;
}
strContinue = ReaderData.getStringInput("Do you want to continue? [Y/N]: ");
System.out.println();
System.out.println();
if (strContinue.equals("n"))
{
System.out.println("\n" + "You have inputted: "+ strInputs + "\n" + "\n" + "\n" + "Thank you for using this program, Goodbye!" + "\n" + "\n");
}
}
while(strContinue.equals("y"));
}
/*
*Method name: getOnes
*Description: This method basically converts the numeric ones digit into it's equivalent words.
* As you can see in the codes, it is quite simple how the algorithm works. It tells
* that if this numeric input by the user is for example 1, it'll convert it to it's
* default stored word, which is one. The same goes for the rest of the numbers.
*Arguments: none
*Return Type: ones
*Known Bugs:none
*/
public String getOnes(String Ones)
{
int iConvert = Integer.parseInt(Ones);
if (iConvert == 0)
{
Ones = "Zero";
}
else if (iConvert == 1)
{
Ones = "One";
}
else if (iConvert == 2)
{
Ones = "Two";
}
else if (iConvert == 3)
{
Ones = "Three";
}
else if (iConvert == 4)
{
Ones = "Four";
}
else if (iConvert == 5)
{
Ones = "Five";
}
else if (iConvert == 6)
{
Ones = "Six";
}
else if (iConvert == 7)
{
Ones = "Seven";
}
else if (iConvert == 8)
{
Ones = "Eight";
}
else if (iConvert == 9)
{
Ones = "Nine";
}
return Ones;
}
/*
public String getTens()
{
// codes here
}
public String getHundreds()
{
// codes here
}
public String getThousands()
{
// codes here
}
*/
}
------------------------
I'm still looking for a way to find the tens, hundreds and thosands value
eg.
45 = forty five dollars
123 = one hundred and twenty three dollars
3241 = three thousand and two hundred and forty one dollars
Any ideas? please help.
Thanks.