A A A
Plain text Report abuse
Write a program that converts a Roman numeral to it's integer equivalent and vice versa converts an integer to it's Roman numeral equivalent. You will need to write one class, named your initials_Roman (eg. Mine would be TS_Roman), that does the following: 1. Stores a Roman numeral input value as a String (e.g. CVIII). 2. Stores the Roman numerals' integer equivalent (e.g. CVIII = 108), so you could use an int or Integer attribute. 3. Has a method (e.g. convertRomanToInt) which converts and stores the Roman numerals' integer equivalent value. 4. Has a method (e.g. convertIntToRoman) which converts and stores an integers' Roman numeral equivalent value. 5. Has a method which outputs the Roman numeral String value and it's integer equivalent. 6. The your initials_Roman class will NOT have a main method! 7. If your program has an isValid method which when passed a Roman numeral as a parameter, returns true or false indicating whether or not the passed Roman numeral is a valid Roman numeral (e.g. CVIII is valid and would return true, CCMVVX is invalid and would return false). You will need to write a second class that uses the your initials_Roman class much like the ClockTester and Clock example that we reviewed in class today. So, the second class you write, named your initials_RomanTester, will be the tester class which creates instances of the your initials_Roman class object and calls the appropriate methods on those your initials_Roman class objects. Your your initials_RomanTester class will need to do the following: 1. It will have a getInput method which will be passed a String representing what input the user is being prompted for (i.e. either a Roman Numeral value or an Integer value). This should be the only place in the program that input is prompted for. So whether you use the Scanner class or the JOptionPane.showInputDialog, this should be the only method used to acquire whatever value is input. The getInput method should return whatever input the user has entered as a String. Why would that be the case? What are the only two inputs required for this program??? method signature will probably be public static String getInput(String type) 2. It will have a main method which implements the following algorithm: a) Calls the getInput method twice, once prompting for and returning a roman numeral value to convert and once prompting for and returning an integer value (as a String) to convert. The passed parameter value will be used by the method to prompt the user accordingly (i.e. “Please enter a Roman Numeral value: “ or “Please enter an Integer value: “ b) Once the main has those 2 input values it will need to: i. Create an instance of a your initials_Roman class object. ii. If your your initials_Roman class has the isValid method call it to make sure you're trying to convert a valid Roman numeral. If it's NOT valid, output an error message of some sort. iii. Call the appropriate conversion method on that object. iv. Call the output method on the object to display the results of the conversion. c) You may want to implement some sort of loop that controls executing the above cycle over and over again until some exit condition. This is not required but makes testing easier.Roman numerals follow a fairly strict rule in sequence in order to reduce ambiguity in numbers. To create Roman numerals we must first define which letters represent which values, and what exceptions there are to the basic rule. The following table shows the Roman Numeral Letters and their associated integer value: Roman Numeral Letter Integer Equivalent I 1 V 5 X 10 L 50 C 100 D 500 M 1000 The basic rule is that Roman Numerals are read from left to right, larger valued letters precede smaller valued letters, multiple letters in a row represent multiples of that value. The following table provides some examples, which could be used to test your programs: Roman Numeral Integer Equivalent I 1 II 2 III 3 VIII 8 XVI 16 CVII 107 CCVII 207 DCCVII 707 MDCCVII 1707 NOTE: Your programs DO NOT NEED to handle the single exception to the basic rule which isthat if a larger value letter is preceded by a single smaller value letter, then the combination represents the value of the larger value letter minus the value of the smaller value letter. This exception only holds true for the values 4, 9, 90, 400 and 900, which are written as IV, IX, XL, XC, CD and CM respectively.