/* * Program class to test out the two * different Roman Numeral Classes * * CS112 * * Christine Papadakis-Kanaris * */ public class TestRomanNumerals { /* * Separate driver main method to test * the methods of our classes */ public static void main(String[] args) { System.out.printf("Simple static calls:\n"); System.out.printf("\tX + XI = %d\n", RomanNumeralStatic.add("X", "XI")); System.out.printf("\tLXI = %d\n", RomanNumeralStatic.convert("LXI")); System.out.printf("Roman Object Manipulation\n"); RomanNumeral r1 = new RomanNumeral("X"); RomanNumeral r2 = new RomanNumeral("VI"); RomanNumeral r3 = new RomanNumeral("XIV"); System.out.printf("\t%s + %s = %d\n", r1, r2, r1.add(r2)); System.out.printf("\t%s + %s = %d\n", r1, r3, r1.add(r3)); System.out.printf("\t%s + %s = %d\n", r2, r3, r2.add(r3)); // Create an array of roman numeral object from // the array of roman numeral strings // String[] roman_strings = {"X", "LX", "XII", "IX", "XXI"}; RomanNumeral[] roman_objects = new RomanNumeral[roman_strings.length]; for (int k = 0 ; k < roman_strings.length ; k++) { roman_objects[k] = new RomanNumeral( roman_strings[k] ); } System.out.printf("Printing out roman numeral strings with their decimal values\n"); for (int n = 0 ; n < roman_strings.length ; n++) { System.out.printf( "\t%s -> %d\n" , roman_strings[n] , RomanNumeralStatic.convert(roman_strings[n])); } System.out.printf("Printing out roman numeral objects with their decimal values\n"); for (int n = 0 ; n < roman_objects.length ; n++) { System.out.printf( "\t%s -> %d\n" , roman_objects[n] , roman_objects[n].getNumericalValue() ); } } // end of main() method } // end of class defintion