主题:求救啊,java作业不会做,谁来帮忙一下啊?
下面是作业内容,谁能帮我做出来啊?万分感谢啊
Exceptions
Roman Numeral Math
For this assignment you will create an application to parse Roman numerals.
Roman numerals represent non-negative integers using this conversion table:
1 I 2 II
3 III 4 IV
5 V 10 X
50 L 100 C
500 D 1000 M
Other values are made by concatenating the characters dened in the table
e.g., 2647 converts to MMDCXLVII.
You will need to create three classes
1. RomanNumeral.java.
Each RomanNumeral object stores its own value in decimal and Roman
numerals.
Methods of the class are:
constructor: RomanNumeral(int decimalValue).
Creates a RomanNumeral object storing this decimalValue and its
corresponding Roman characters. Example:
RomanNumeral rn = new RomanNumeral(14)
stores both the number 14 and the String \XIV". Throws an Illegal-
RomanNumeralException if decimalValue is < 1.
constructor: RomanNumeral(String strValue). Throws an IllegalRo-
manNumeralException if the string contains illegal characters.
+ add(RomanNumeral numeralToAdd): int
+ subtract(RomanNumeral numeralToSubtract): int
throws IllegalRomanNumeralException if the resulting value is less
than one.
+ multiply(RomanNumeral numeralToMultiply): int
+ divide(RomanNumeral numeralToDivide): int
uses integer division and throws an IllegalRomanNumeralException
if the resulting value is less than one.
+ getChars(): String, the Roman characters of this object
+ getDecimal():int, the integer value of this object
+ static toRoman(decimalValue: int): String, the Roman chars
+ static toDecimal(strValue: String) int, the integer value
2. IllegalRomanNumeralException.java. Exception class specic to Roman-
Numeral objects
1
3. RomanMath.java
An application to test your RomanNumeral class and its exception.
Output from RomanMath might be:
Let's do some Roman Math. Give me two Roman numerals.
CCXLVI
XXVII
You entered 346 and 27
What shall I do with them?
1. Add 2.Subtract 3.Multiply 4. Divide
4
The result of your division is 12
Want to do some more math?
y
Enter the operation number
2
The result of your subtraction is 319
Want to do some more math?
n
I can convert numbers too.
Give me a decimal and I'll give you its Roman.
659
That was easy it's DCLIX
Try another?
n
Give me a Roman and I'll give you its decimal:
CMXXII
That was easy it's 922
Try another?
y
BCXVI
That is not a valid Roman number.
Try another?
y
MCXII
That was easy it's 1112
Try another?
n
1. Important features:
Your program should continue to prompt for numerals until two valid
numbers have been entered. Hint: use the catch to call a getInput
method.
Your program should allow the user to continue until he/she wants
to stop. It should not stop as a result of invalid input.
2
To be submitted through Blackboard:
1. UML Class Hierarchy diagram
2. Source code for RomanMath.java; RomanNumeral.java and IllegalRoman-
NumeralException.java
3. Output from executing RomanMath
Please do not zip these les. You can copy and paste them into the submission
box or attach the les (.java not .class) Only one member of the team needs to
submit the solutions, but be sure to include the names of both team members
on all submissions.
Comments must be included in a format suitable for the javadoc utility to
generate documentation.
Exceptions
Roman Numeral Math
For this assignment you will create an application to parse Roman numerals.
Roman numerals represent non-negative integers using this conversion table:
1 I 2 II
3 III 4 IV
5 V 10 X
50 L 100 C
500 D 1000 M
Other values are made by concatenating the characters dened in the table
e.g., 2647 converts to MMDCXLVII.
You will need to create three classes
1. RomanNumeral.java.
Each RomanNumeral object stores its own value in decimal and Roman
numerals.
Methods of the class are:
constructor: RomanNumeral(int decimalValue).
Creates a RomanNumeral object storing this decimalValue and its
corresponding Roman characters. Example:
RomanNumeral rn = new RomanNumeral(14)
stores both the number 14 and the String \XIV". Throws an Illegal-
RomanNumeralException if decimalValue is < 1.
constructor: RomanNumeral(String strValue). Throws an IllegalRo-
manNumeralException if the string contains illegal characters.
+ add(RomanNumeral numeralToAdd): int
+ subtract(RomanNumeral numeralToSubtract): int
throws IllegalRomanNumeralException if the resulting value is less
than one.
+ multiply(RomanNumeral numeralToMultiply): int
+ divide(RomanNumeral numeralToDivide): int
uses integer division and throws an IllegalRomanNumeralException
if the resulting value is less than one.
+ getChars(): String, the Roman characters of this object
+ getDecimal():int, the integer value of this object
+ static toRoman(decimalValue: int): String, the Roman chars
+ static toDecimal(strValue: String) int, the integer value
2. IllegalRomanNumeralException.java. Exception class specic to Roman-
Numeral objects
1
3. RomanMath.java
An application to test your RomanNumeral class and its exception.
Output from RomanMath might be:
Let's do some Roman Math. Give me two Roman numerals.
CCXLVI
XXVII
You entered 346 and 27
What shall I do with them?
1. Add 2.Subtract 3.Multiply 4. Divide
4
The result of your division is 12
Want to do some more math?
y
Enter the operation number
2
The result of your subtraction is 319
Want to do some more math?
n
I can convert numbers too.
Give me a decimal and I'll give you its Roman.
659
That was easy it's DCLIX
Try another?
n
Give me a Roman and I'll give you its decimal:
CMXXII
That was easy it's 922
Try another?
y
BCXVI
That is not a valid Roman number.
Try another?
y
MCXII
That was easy it's 1112
Try another?
n
1. Important features:
Your program should continue to prompt for numerals until two valid
numbers have been entered. Hint: use the catch to call a getInput
method.
Your program should allow the user to continue until he/she wants
to stop. It should not stop as a result of invalid input.
2
To be submitted through Blackboard:
1. UML Class Hierarchy diagram
2. Source code for RomanMath.java; RomanNumeral.java and IllegalRoman-
NumeralException.java
3. Output from executing RomanMath
Please do not zip these les. You can copy and paste them into the submission
box or attach the les (.java not .class) Only one member of the team needs to
submit the solutions, but be sure to include the names of both team members
on all submissions.
Comments must be included in a format suitable for the javadoc utility to
generate documentation.