Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions

Question

Introduce cumulative risk and developmental cascade models.

Answered: 1 week ago

Question

c. What personal behavior is acceptable and nonacceptable?

Answered: 1 week ago

Question

Develop skills for building positive relationships.

Answered: 1 week ago

Question

Describe techniques for resolving conflicts.

Answered: 1 week ago

Question

Give feedback effectively and receive it appropriately.

Answered: 1 week ago