In relation to my last question about setting the TextView as the method output this question is about splitting the integer into separate digits. My Roman Numeral program works by using the translator method here:
'public static String translator(int integer) {
String result = "";
LinkedList<String> stack = new LinkedList<String>();
// if (integer > 0 && integer <= 4999) {
//ArrayList<Integer> placement = new ArrayList<Integer>();
int place = (int) Math.log10(integer);
for (int i = 0; i <= place; i++) {
//while(integer > 0){
//System.out.println(integer);
int placeOfValue = integer % 10;
//stack.push(placeOfValue);
//System.out.print(stack);
//System.out.print(placeOfValue +":" + i);
String placement = "";
switch (i) {
case 0:
placement = ones(placeOfValue);
break;
case 1:
placement = tens(placeOfValue);
break;
case 2:
placement = hundreds(placeOfValue);
break;
case 3:
placement = thousands(placeOfValue);
break;
default:
break;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
stack.push(placement);
}
integer = integer / 10;
//System.out.print(placement);
// System.out.println(placement.size());
//}
// for(int j = 0; j < placement.size(); j++){
// double tenthPower = Math.floor(Math.log10(placement.get(j)));
// double place = Math.pow(10, tenthPower);
// System.out.println(place);
//
// }
// }
while (!stack.isEmpty()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
result += stack.pop();
//System.out.print(stack.pop());
}
}
// } else {
// System.out.println("Please enter an integer between 0 and 4,999.");
// }
}
return result;
}
`
The translator method works by going through the for loop which will loop through the size of the integer then assigning the digit a given placement. From the placement it will then look through the placement methods and return the numeral. Since the integers are added in reverse for the LinkedList I have pushed the stack and popped it based on this post How to get the separate digits of an int number? to get the correct order. However the program continues to print out the numerals in reverse order which is not what I want. I have debugged the program but with no luck it feels like something is off with the pop method and adding it to the output but I can't figure out what.