New programming student over here. Trying to convert a roman numeral input to it's integer value. I have been using this post over here as a guide. Here's the thing, I haven't learned about hashtables or enums so I can't use that in my code. Let me show you what I have so far:
public static String romanInput(int number) {
Scanner numberInput = new Scanner (System.in);
System.out.print("Enter a roman numeral in uppercase: ");
String userInput = numberInput.next();
return userInput;
}
public static int numberConversion(String romanNumeral) {
int result = 0;
for (int x = romanNumeral.length() - 1; x >= 0 ; x--) {
char romanConvert = romanNumeral.charAt(x);
switch (romanConvert) {
case 'I':
result += 1;
break;
case 'V':
result += 5;
break;
case 'X':
result += 10;
break;
case 'L':
result += 50;
case 'C':
result += 100;
break;
case 'D':
result += 500;
break;
case 'M':
result += 1000;
break;
}
}
return result;
}
public static int numberOutputs(String input, int converted) {
String input = romanInput(output);
int
}
public static void main(String[] args) {
}
}
I haven't even gotten to the point where I can test this out, but I know what I am doing is wrong. I know that if the roman numerals entered are in decreasing value or in equal value, then you will add the values together. I know that if the number is less than the number that follows it, you wold subtract it's value. So I'm guessing the algorithm would be something like:
if (first number >= second number) {
return (first number + second number)
} else {
return (second number - first number) };
Is that what my conversion algorithm should look like?
Let me give you some more detail on what my assignment states: This program must have 3 methods and a main method!
- Write a method that takes input from the user and passes it to a conversion method.
- Write a method that yields the numeric value of each of the letters (conversion method).
- Write a method that outputs the number the user entered and the converted number.
- Write a main method to test the 3 methods.
HINT: Use a single dimensional array!
So once I figure out how to write the algorithm, I then need to construct a method that outputs the number the user entered and the converted number. Would that just be something like:
System.out.println("The number you entered was: " +romanInput(input));
and then do the same for the converted roman numeral. What am I supposed to return in that method?
I don't want to just copy over what is over at the other post because I'm trying to understand how this program is supposed to work. This is an online course, so unfortunately I only have a book as a guide for this assignment so I would really appreciate help from a more experienced programmer.