Question: Java Assignment is to write a program that converts Arabic numerals to Roman numerals. The program should be able to handle integers between 1 and

Java Assignment is to write a program that converts Arabic numerals to Roman numerals. The program should be able to handle integers between 1 and 3999. You should display an error message for numbers outside of this range. Allow the user to continue converting values until the enter -1 to quit. The code for doing the conversion should be contained within a metody with the following signature: public static String ArabicToRoman(int arabic);

I have the following code completed but it's not outputting the response into Roman.

import java.util.Scanner;

public class RomanNumerals {

private static String ArabicToRoman (int num) {

String [] romanLetters = {"I", "IV", "V", "IX", "X", "L", "XC", "C", "D", "CM", "M"} ;

int [] romanValues = {1, 4, 5, 9, 10, 50, 90, 100, 500, 900, 1000};

String romanOutput = "";

for (int i = 0; i < romanValues.length; i++) {

int quotient = num / romanValues[i];

if (quotient == 0) continue;

if (quotient == 4)

romanOutput = romanOutput+romanLetters[i]+romanLetters[i-1];

else

romanOutput += new String(new char[quotient]).replace("\0",romanLetters[i]);

num = num % romanValues[i];

}

return romanOutput;

}

public static void main(String[] args)

{

Scanner s = new Scanner(System.in);

System.out.print("Enter an integer (-1 to quit):");

int num = s.nextInt();

while (num!=-1) {

if(num<+ 0 || num > 3999)

System.out.println ("Invalid input. Please enter again.");

else

System.out.println(ArabicToRoman(num));

System.out.print("Enter an integer (-1 to quit):");

num = s.nextInt();

}

}

}

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!