I'm a relatively new student learning Java programming, but I'd like to ask for some help. The error I'm receiving in my code is stating "variable romanNumeral might not have been initialised."
The intent for this program is for a user to enter a number from 1-39 and then have the appropriate roman numeral value displayed to the user via a dialog box. The code is not complete yet, as I've yet to find a solution to this problem due to the application not letting me compile my code.
Here is the code:
public class exercise4 extends Actor
{
int userNum;
public void act()
{
intInput(userNum);
}
public String intInput(int userNum)
{
String userInput;
String romanNumeral;
userInput = JOptionPane.showInputDialog("Please enter a number to be converted into Roman Numerals.");
userNum = Integer.parseInt(userInput);
switch(userNum)
{
case 1: romanNumeral = "I";
break;
case 2: romanNumeral = "II";
break;
case 3: romanNumeral = "III";
break;
case 4: romanNumeral = "IV";
break;
case 5: romanNumeral = "V";
break;
case 6: romanNumeral = "VI";
break;
case 7: romanNumeral = "VII";
break;
case 8: romanNumeral = "VIII";
break;
case 9: romanNumeral = "IX";
break;
case 10: romanNumeral = "X";
break;
case 11: romanNumeral = "XI";
break;
case 12: romanNumeral = "XII";
break;
case 13: romanNumeral = "XIII";
break;
case 14: romanNumeral = "XIV";
break;
case 15: romanNumeral = "XV";
break;
case 16: romanNumeral = "XVI";
break;
case 17: romanNumeral = "XVII";
break;
case 18: romanNumeral = "XVIII";
break;
case 19: romanNumeral = "XIX";
break;
case 20: romanNumeral = "XX";
break;
case 21: romanNumeral = "XXI";
break;
case 22: romanNumeral = "XXII";
break;
case 23: romanNumeral = "XXIII";
break;
case 24: romanNumeral = "XXIV";
break;
case 25: romanNumeral = "XXV";
break;
case 26: romanNumeral = "XXVI";
break;
case 27: romanNumeral = "XXVII";
break;
case 28: romanNumeral = "XXVIII";
break;
case 29: romanNumeral = "XXIX";
break;
case 30: romanNumeral = "XXX";
break;
case 31: romanNumeral = "XXXI";
break;
case 32: romanNumeral = "XXXII";
break;
case 33: romanNumeral = "XXXIII";
break;
case 34: romanNumeral = "XXXIV";
break;
case 35: romanNumeral = "XXXV";
break;
case 36: romanNumeral = "XXXVI";
break;
case 37: romanNumeral = "XXXVII";
break;
case 38: romanNumeral = "XXXVIII";
break;
case 39: romanNumeral = "XXXIX";
break;
}
return romanNumeral;
}
}