I'ma noob and need some help from the pros.
For school I gotta make a program to convert numbers into roman numerals 1-10 and return an error if its not 1-10.
Got it all pretty much figured out but I want to know how to have it where if someone enters the wrong number, it returns the error then will restart the program from the start again so they can enter the right number. Maybe even a dialogue box at the end asking if they would like to retry or not.
Any advice or help would be greatly appreciated!
Thanks!
Heres what i got so far
import javax.swing.JOptionPane; // Needed for JOptionPane
/**
Chapter 3.1 Roman Numerals
*/
public class Chapter3dot1
{
public static void main(String[] args)
{
int num;
String input;
input = JOptionPane.showInputDialog("Enter a number between 1 and 10 " +
"and I will convert it to a Roman numeral: ");
num = Integer.parseInt(input);
if (num == 1)
JOptionPane.showMessageDialog(null, "I");
else if (num == 2)
JOptionPane.showMessageDialog(null, "II");
else if (num == 3)
JOptionPane.showMessageDialog(null, "III");
else if (num == 4)
JOptionPane.showMessageDialog(null, "IV");
else if (num == 5)
JOptionPane.showMessageDialog(null, "V");
else if (num == 6)
JOptionPane.showMessageDialog(null, "VI");
else if (num == 7)
JOptionPane.showMessageDialog(null, "VII");
else if (num == 8)
JOptionPane.showMessageDialog(null, "VIII");
else if (num == 9)
JOptionPane.showMessageDialog(null, "IX");
else if (num == 10)
JOptionPane.showMessageDialog(null, "X");
else //error message
JOptionPane.showMessageDialog(null, "Not good at following instructions?" +
"\nI said enter a number between 1 and 10!");
System.exit(0);
}
}