/* * Class definition which can be used to * create instances of Roman Numeral objects. * * CS112 * * Christine Papadakis-Kanaris */ public class RomanNumeral { // declare the attributes (data members) // of the class private int numericalValue; private String stringValue; // Constructors public RomanNumeral(String stringValue) { this.stringValue = stringValue; // Note: // // Since we had already written a method to // convert a roman numeral string into // its decimal equivalent in our static // class API, we can use it // and do not need to duplicate the code // in this class. // numericalValue = RomanNumeralStatic.convert(stringValue); } // // Accessor Methods // public int getNumericalValue() { return( numericalValue ); } // // Class Methods // public String toString() { return this.stringValue; } public boolean equals(RomanNumeral other) { return (this.numericalValue == other.numericalValue); } public int add(RomanNumeral other) { return this.numericalValue + other.numericalValue; } /* * Local main method to test * the methods of our class. */ public static void main(String[] args) { RomanNumeral x = new RomanNumeral("X"); RomanNumeral y = new RomanNumeral("IX"); System.out.printf("%s + %s = %d\n", x, y, x.add(y)); System.out.print( "Testing equality, the objects are " ); if ( !x.equals(y) ) System.out.print( "not " ); System.out.println( "equal!" ); } } // end of class definition