I'm a new programming student and my assignment is to convert the input of a Roman Numeral to it's integer value. Here is what I have been given:
Write a program that converts a Roman number such as MCMLXXVIII to its decimal number representation. 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!
Convert a string as follows:
• Look at the first two characters. If the first has a larger value than the second, then simply convert the first.
• Call the conversion method again for the substring starting with the second character.
• Add both values. o If the first one has a smaller value than the second, compute the difference and add to it the conversion of the tail.
Now I am struggling trying to figure out what to do for my conversion method. Here is what I have written so far:
public static String romanInput(String number) {
Scanner numberInput = new Scanner (System.in);
System.out.print("Enter a roman numeral: ");
String userInput = numberInput.next();
return userInput;
}
public static int numberConversion(int number) {
int romanConv = 0;
char[] romanChar = {1, 5, 10, 50, 100, 500, 1000};
for (int i = 0; i < romanChar.length; i++)
}
You could see that I have already written the method that takes the input from a user. I think I did this correctly. However, I don't know what to do for this conversion method. It says to use a single dimensional array so that's what I did over here:
char[] romanChar = {1, 5, 10, 50, 100, 500, 1000};
Those are supposed to be the values of I, V, X, L, C, D, and M. I'm really just confused as where to go from there and I would appreciate it if someone can help me out.