# Writing Programs in Java

The programming assignment for this module is programming exercise #7 on pages 861 and 862, with the following modifications.

- For part 'a' the source code for class Roman is attached to this assignment. You do not have to include the method decimalToRoman as you modify this class. Also, class Roman is not used in your test program.

- In part 'b' be sure to throw exceptions for the conditions specified when subtracting and dividing. The Roman's grasp of math was very limited (why else would they have developed such an awkward system for recording numbers?) and never considered negative numbers. Basically all they did was count things.

- While your program will only use the ExtendedRoman class you must submit three files for this assignment: Roman, ExtendedRoman, and your test program.

Source code for class Roman: Roman.java (original source code attached)

Here is the assignment as written in the book:

a.) Modify the definition of the class Roman so that the data members are declared as protected. Also incluse the method decimalToRoman, which converts the decimal number (the decimal number must be a positive integer) to an equivalent Roman numeral format. Write the definition of the method decimalToRoman. Your definition of the class Roman must contain the method toString, which returns the string containing the number in Roman format. For simplicity, we assume that only the letter I can appear in front of another letter and that it appears only in front of the letters V and X. For example, 4 is represented as IV, 9 is represented as IX, 39 is represented as XXXIX, and 49 is represented as XXXXIX. Also, 40 is represented as XXXX, 190 is represented as CLXXXX, so on.

b.) Derive the class ExtendedRoman from the class Roman to do the following. In the class ExtendedRoman, include the methods add, subtract, multiply, and divide so that arithmetic operations can be performed on Roman numerals.

To add (subtract, multiply, or divide) Roman numerals, add (subtract, multiply, or divide, respectively) their decimal representations and then convert the result to the Roman numeral format. For subtraction, if the first number is smaller than the second number, throw the exception, "Because the first number is smaller than the second, the numbers cannot be subtracted." Similarly, or division, the numerator must be larger than the denominator.

c.) Write the definition of the methods add, subtract, multiply, and divide as described in part B. Also, your definition of the class ExtendedRoman must contain the method toString that returns the string containing the number in Roman format.

d.) Write a program to test various operations on your class ExtendedRoman.

Â© BrainMass Inc. brainmass.com December 16, 2022, 9:01 am ad1c9bdddfhttps://brainmass.com/computer-science/java/writing-programs-in-java-466882

#### Solution Summary

The following program helps write various programs in Java.