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.

Step by Step Solution

3.45 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ANSWER def valuer if r I return 1 if r V return 5 if r X return 10 if ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Concepts Late Objects Questions!