Question: (question is at the bottom after the code) import javax.swing.JOptionPane; public class RomanNumerals { public static void main(String[] args) { // TODO Auto-generated method stub

(question is at the bottom after the code)

import javax.swing.JOptionPane;

public class RomanNumerals {

public static void main(String[] args) {

// TODO Auto-generated method stub

final String title =("Conversion of Roman numerals");

final String task =("Enter a Roman numeral between \"I\" and \"XV\"");

String roman=JOptionPane.showInputDialog(null,task,title,JOptionPane.QUESTION_MESSAGE);

char firstCharacter=roman.charAt(0);

char secondCharacter=roman.charAt(1);

char thirdCharacter=roman.charAt(2);

char fourthCharacter=roman.charAt(3);

int decimal;

if (firstCharacter !=('I')||firstCharacter!=('i')||firstCharacter!=('V')||firstCharacter!=('v')||firstCharacter!=('X')||firstCharacter!=('x'))

JOptionPane.showMessageDialog(null, "Please input a valid roman numeral from I to XV.");

if (firstCharacter ==('I') || firstCharacter==('i'))

{if (secondCharacter==('I')||secondCharacter==('i'))

{if (thirdCharacter==('I')||thirdCharacter==('i'))

decimal = 3;}

else if (secondCharacter==('V')||secondCharacter==('v'))

decimal = 4;

else if (secondCharacter==('X')||secondCharacter==('x'))

decimal = 9;

decimal = 2;}

decimal = 1;

if (firstCharacter==('V') || firstCharacter==('v'))

{if (secondCharacter==('I')||secondCharacter==('i'))

{if (thirdCharacter==('I')||thirdCharacter==('i'))

{if (fourthCharacter==('I')||fourthCharacter==('i'))

decimal = 8;}

decimal = 7;}

decimal = 6;}

decimal = 5;

if (firstCharacter==('X')||firstCharacter==('x'))

{if (secondCharacter==('I')||secondCharacter==('i'))

{if (thirdCharacter==('I')||thirdCharacter==('i'))

{if (fourthCharacter==('I')||fourthCharacter==('i'))

decimal = 13;}

else if (thirdCharacter==('V')||thirdCharacter==('v'))

decimal = 14;

decimal = 12;}

else if (secondCharacter==('V')||secondCharacter==('v'))

decimal = 15;

decimal = 11;}

decimal = 10;

JOptionPane.showMessageDialog(null, "The decimal value for the Roman numeral "+roman+" is: ........"+decimal+ "........",title,JOptionPane.INFORMATION_MESSAGE);

//program terminates without displaying JOptionPane showing the decimal value

//not sure what i did wrong because this makes sense to me but obviously there's something im not understanding

//i refuse to put any more thought into this waist of time, this is my best attempt at it

// originally tried using else if in the code but it kept flagging it as an error

System.exit(0);}

}

My question is, what am I doing wrong? For this assignment we have to use if-else statements, that's why this is so much longer than it needs to be. Probably don't need me to tell you but this is with java eclipse. please help

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!