Question: Write a program that converts a Roman number such as MCMLXXVIII to its decimal number representation. Hint: First write a method that yields the numeric
Write a program that converts a Roman number such as MCMLXXVIII to its decimal number representation. Hint: First write a method that yields the numeric value of each of the letters. Then use the following algorithm:
total = 0
str = roman number string
While str is not empty
If str has length 1, or value(first character of str) is at least value(second character of str)
Add value(first character of str) to total.
Remove first character from str.
Else
difference = value(second character of str) - value(first character of str)
Add difference to total.
Remove first character and second character from str.
Write the program in Java. Use simple methodology in order to help with the understanding of the problem. Also if possible add comments to explain the steps used. Thanks.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
