import java.io.*;
public class SkeletonSpell {
static String sNumber = "";
static String prefix = "";
static String digit = "";
public static void main(String [] args) throws IOException {
int choice;
//double num=0;
do{
System.out.println("************************************");
System.out.println("1.Enter number in digits");
System.out.println("2.Display summary of number in words");
System.out.println("3.Exit");
System.out.println("************************************");
System.out.println("Please enter your choice(1000 to exit): ");
choice=CspInput.readInt();
switch(choice){
case 1:
for(int i=0;i<10;i++)
{
System.out.println("Enter number between -999.99 to 999.99");
System.out.println("Enter number 1000 to stop");
InputStreamReader isr = new InputStreamReader(System.in);
// BufferedReader br = new BufferedReader(isr);
System.out.print("Enter a number: ");
sNumber = CspInput.readString();
double d = Double.valueOf(sNumber.trim()).doubleValue();
if (d == 1000)
{
sNumber = "0";
break;
}
if ((d < -999.99) || (d > 999.99))
{
System.out.println("Invalid number entered.");
break;
}
}
main(null);
case 2:
int iNumber = Integer.parseInt(sNumber);
convert(iNumber);
System.out.println("The number " + "is" + digit);
break;
case 3:
System.out.println("thank you for using number speller");
break;
}
}while(choice!=3);
}
private static final String[] tensNames = {
"",
" ten",
" twenty",
" thirty",
" fourty",
" fifty",
" sixty",
" seventy",
" eighty",
" ninety"
};
private static final String[] numNames = {
"",
" one",
" two",
" three",
" four",
" five",
" six",
" seven",
" eight",
" nine",
" ten",
" eleven",
" twelve",
" thirteen",
" fourteen",
" fifteen",
" sixteen",
" seventeen",
" eighteen",
" nineteen"
};
private static String convertLessThanOneThousand(int number) {
String digit;
if (number % 100 < 20){
digit = numNames[number % 100];
number /= 100;
}
else {
digit = numNames[number % 10];
number /= 10;
digit = tensNames[number % 10] + digit;
number /= 10;
}
if (number == 0) return digit;
return numNames[number] + " hundred" + digit;
}
public static String convert(int number) {
/* special case */
// if (number == 0) { System.out.println("zero"); }
if (number < 0) {
number = -number;
prefix = "negative";
}
int place = 0;
do {
int n = number % 1000;
if (n != 0){
String s = convertLessThanOneThousand(n);
//soFar = s + majorNames[place] + soFar;
}
place++;
number /= 1000;
} while (number > 0);
return (prefix + digit).trim();
}
}
this is my whole program..but i cant seems to display the output..seriously need help...and also how do i spell . -> point eg. i type 2.1 it spells two point one?