You are to design and implement a Roman numeral calculator. The subtractive Roman numeral notation commonly in use today was used only rarely during the time of the Roman Republic and Empire. For ease of calculation, the Romans most frequently used a purely additive notation in which a number was simply the sum of its digits (4 equals IIII in this notation, not IV). Each number starts with the digit of highest value and ends with the digit of smallest value. You will use this notation in this program.

You program inputs two Roman numbers and an arithmetic operator and displays the result of the operation, Also as a Roman number. The values of the Roman digits are as follows:

I 1
V 5
X 10
L 50
C 100
D 500
M 1000

Thus, the number MDCCCCLXXXXVI represents 1996, because 1996 is really consists of:

1000+500 + 100 + 100 + 100 + 100 + 50 + 10 + 10 + 10 + 10 + 5+1.
M+D+C+ C+ C+ C+L+X+X+X+X+V+I

The arithmetic operators that your program should recognize in the input are +, - *% and/. These should perform the Java operations of INTEGER addition, subtraction, multiplication, modulus and division.

One way of approaching this problem is to convert the Roman numbers into integers, perform the required operation, and then convert the result back into a Roman number for printing.

The following might be a sample run of the program:

MCCXXVI The first number is (1226)
LXVIIII The second number is (69)

The desired arithmetic operation: +

MCCLXXXXV The result is (1295)

The program should check for errors in the input, such as illegal digits or arithmetic operators. It should display an error message when these errors appear. Assume the input numbers are in purely additive form - this is, digits are only followed by digits of the same or lower value. No need for edit checking.

The calculator will be a form with 3 text boxes for data entry, 3 labels for the display and 14 buttons, 7 buttons for the roman numbers, 5 buttons for the operations (*,/,%, +, and -), one button for the equal, one button for clearing the textboxes and the labels,

Sample calculator: see image.

As you can see in the sample image, the calculator has 3 text boxes, Romanl, Roman2, and Result. Next to each textbox there is a label that will be used to display the integer value of each roman number. The Result textbox, will have the result of the two Romans based on the operation chosen. The CE button will clear everything. The result and the labels should be not editable.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.