I'd create a function that takes a number as an input, uses a for loop with str.length-1
that iterates through each number starting with the last, obtain the integer itself using str.charAt(i)
and as you said use a switch statement to turn the number into a String. Then you can compile them using the +=
operator
Something like this should work
String numberSentence (int input) {
String total = new String();
String inputS = input.toString();
int min = 0;
if(inputS.charAt(0) == '-'){
total.concat("Minus ")
min = 1;
}
for(int i = inputS.length-1; i >= min; i--) {
total.concat(stringify(inputS.charAt(i)));
}
return total.toString();
}
String stringify (String letter) {
String word;
switch(letter) {
case "1": word = "one"; // Don't forget the "" !
break;
... Continued ...
}
return word;
}
This same approach can be used when the input is not an int