Lab Assignment #2 Creating Classes

Lab Assignment #2
Creating Classes
The purpose of this lab is to gain experience in the design and implementation of a simple Java class. You will create a class definition and write a simple main method that will test the methods of your class to ensure they work as expected.
The required task is to create a class definition for the concept of a Roman numeral. When a Roman numeral object is declared, it should hold a representation of the Roman numeral (e.g., MMXV) and provide the following functionality:
• A constructor that initializes the Roman numeral to the value supplied as the parameter to the constructor in Roman numeral format
• A constructor that initializes the Roman numeral to the value supplied as the parameter to the constructor in decimal format
• A method that returns the value of the Roman numeral
• A method that returns the decimal equivalent of the value of the Roman numeral
Note: a Roman numeral object is only allowed to permanently store the Roman numeral representation of the number (i.e., adding an int member for the decimal equivalent is not allowed).
Your test program must create Roman numeral objects and enable the user to sufficiently test the class methods for correctness. I/O can be console based – e.g., you may want to prompt the user for a Roman numeral, create a Roman numeral object and then output the numeral in both Roman numeral and decimal format.
The extended task is to add functionality to the class to add Roman numerals. Note to get any credit for this method this addition must be done using the Roman numeral format of the numbers, not by converting them to decimal values and adding those. Your test code should be extended to allow the user to exercise the add function as many times as desired.
As a reminder, these are the decimal values of the Roman numeral “digits”:
M 1000
D 500
C 100
L 50
X 10
V 5
I 1
Submit your project folder (zipped) using the link provided on the assignment section of Blackboard.
Powered by