Write a program that converts anumber entered in Roman numerals to decimal. Your
ID: 3618468 • Letter: W
Question
Write a program that converts anumber entered in Roman numerals to decimal. Your program shouldconsist of a class, say,romanType. An object of typeromanType should do thefollowing:a. Store the number as a Romannumeral.
b. Convert and store the number into decimalform.
c. Print the number as a Roman numeral ordecimal number as requested by the user.
The decimal values of the Roman numerals are:
M 1000
D 500
C 100
L 50
X 10
V 5
I 1
d. Test your program using the followingRoman numerals: MCXIV, CCCLIX, MDCLXVI. Write a program that converts anumber entered in Roman numerals to decimal. Your program shouldconsist of a class, say,romanType. An object of typeromanType should do thefollowing: a. Store the number as a Romannumeral. b. Convert and store the number into decimalform. c. Print the number as a Roman numeral ordecimal number as requested by the user. The decimal values of the Roman numerals are: M 1000 D 500 C 100 L 50 X 10 V 5 I 1 d. Test your program using the followingRoman numerals: MCXIV, CCCLIX, MDCLXVI.
Explanation / Answer
Dear... import javax.swing.JOptionPane; public class Roman { static String romanNumeral; static int decimalNum; static char convertToDecimal; public static void main(String args[]) { Roman demo = new Roman(); demo.convertToDecimal(decimalNum); printRoman(romanNumeral); printDecimal(decimalNum); setRoman(); toString(romanNumeral); } public void convertToDecimal (int other) { romanNumeral = JOptionPane.showInputDialo("Enter a Roman numeral to convert to decimal." + " "+
"Note: Roman numerals are I, V, X, L, C, D and M."+ " " +
"All letters entered will be treated as capitalized."); romanNumeral = romanNumeral.toUpperCase(); int x = 0; do { convertToDecimal = romanNumeral.charAt(x); switch(convertToDecimal) { case 'M': decimalNum += 1000; break; case 'D': decimalNum += 500; break; case 'C': decimalNum += 100; break; case 'L': decimalNum += 50; break; case 'X': decimalNum += 10; break; case 'V': decimalNum += 5; break; case 'I': decimalNum += 1; break; } x++; } while(x<romanNumeral.length()); JOptionPane.showMessageDialog (null, "Roman Numeral Converted to Decimal is: " + decimalNum); } public static void printRoman (String romanNumeral) { System.out.println ("Roman Numeral stored is: " + romanNumeral); } public static void printDecimal (int decimalNum){ System.out.println ("Decimal Number stored is: " + decimalNum); } public static void setRoman () { System.out.println("test Set Roman"); } public void Other(String temp) { temp = ""; } public Roman getCopy(int decimalNum) { Roman temp = new Roman(); Roman.decimalNum = decimalNum; System.out.println(" temp is: " + temp); return temp; } public static String toString(String str) { if (str==romanNumeral) System.out.println("Roman numeral " + romanNumeral + " is equal to Decimal Number " + decimalNum); else System.out.println("Roman numeral " + romanNumeral + " is not equal to Decimal Number " + str); return str; } } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.