Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a RomanNumeral class that encapsulates a Roman numeral value. THE USE OF A

ID: 3536116 • Letter: W

Question

Write a RomanNumeral class that encapsulates a

Roman numeral value. THE USE OF ARRAYS IS NOT PERMITTED. The

methods the class has are: public void read(), public void

set(String), public void set(RomanNumeral), public RomanNumeral

add(RomanNumeral), public RomanNumeral subtract(RomanNumeral),

public RomanNumeral multiply(RomanNumeral), public RomanNumeral

divide(RomanNumeral), public RomanNumeral add(int), public

RomanNumeral subtract(int), public RomanNumeral multiply(int),

public RomanNumeral divide(int), public boolean

equals(RomanNumeral), and public String toString(). Write a private

method to check for valid characters as input. For an added

challenge write a method that exits the program if any non-valid

character combination is entered (I found 43 possible non-valid

character combinations). Although historically there are many ways

to write Roman numerals we will use these rules:

The symbols "I", "X", "C", and "M" can be

repeated three times in succession, but no more. "D", "L", and "V"

can never be repeated.

"I" can be subtracted from "V" and "X" only.

"X" can be subtracted from "L" and "C" only. "C" can be subtracted

from "D" and "M" only. "V", "L", and "D" can never be

subtracted

Only one small-value symbol may be subtracted

from any large-value symbol.

I will provide a main program as the demo.

Un-comment the code I have commented out and implement the

Conversion routines and error checking.


PLEASE USE THIS ROMANNUMERALDEMO

PROVIDED: http://tny.cz/d3895e76

THIS IS WHAT THE OUTPUT SHOULD LOOK LIKE: http://tny.cz/043f68c6


Explanation / Answer

public class RomanNumeralDemo { public static final int ARRAY_SIZE = 5; public static void main(String[] args) { RomanNumeral rn1 = new RomanNumeral ("XXIV"); RomanNumeral rn2 = new RomanNumeral ("III"); RomanNumeral rn4, rn5, rn6, rn7; RomanNumeral rn8 = new RomanNumeral(1999); int number; System.out.println ("Roman Numeral number rn8: " + rn8); RomanNumeral []RomanNumeralArray = new RomanNumeral [ARRAY_SIZE]; System.out.println ("First Roman Numeral number: " + rn1); System.out.println ("Second Roman Numeral number: " + rn2); if (rn1.equals(rn2)) System.out.println ("rn1 and rn2 are Not equal."); rn4 = rn1.add(rn2); rn5 = rn1.subtract(rn2); rn6 = rn1.multiply(rn2); rn7 = rn1.divide(rn2); System.out.println ("rn1 + rn2: " + rn4); System.out.println (rn1 - rn2: " + rn5); System.out.println (rn1 * rn2: " + rn6); System.out.println ("rn1 / rn2: " + rn7); System.out.println(); number = 25; System.out.println("using the integer " + number + " as the argument " + "to the math operators "); rn4 = rn1.add(number); rn5 = rn1.subtract(number); rn6 = rn1.multiply(number); rn7 = rn1.divide(number; System.out.println("rn1 + number: " + rn4); System.out.println("rn1 - number: " + rn5); System.out.println("rn1 * number: " + rn6); System.out.println("rn1 / number: " + rn7); // The next two methods must be written by you. System.out.println ("Fill a roman numeral array with " + ARRAY_SIZE +" roman numerals "); rn7.readRomanNumeralArray(RomanNumeral

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote