this is part of my app where i ask a user if they want to do something. they need to either input a "y" or a "n" for it to do something and if they input something else like a j, 1, 2 , ; , " any other character that isnt "y" or "n" i need it to repeat the questions untill they answer correctly and then to move on with the application.
change1 = JOptionPane.showInputDialog("Change Silo 1 dimensions? (y/n)");
change2 = JOptionPane.showInputDialog(null,"Change Silo 2 dimensions? (y/n)");
if (change1.equalsIgnoreCase("y"))
{
do
{
String input = JOptionPane.showInputDialog("Enter Radius of Silo:1");
try
{
num = Double.parseDouble(input);
}
catch (NumberFormatException nfe)
{
JOptionPane.showMessageDialog(null,"That is not an integer, enter radius again");
}
} while(num < 0 );
Sone.setRadius(num);
do
{
String input = JOptionPane.showInputDialog("Enter height of Silo:1");
try
{
num = Double.parseDouble(input);
}
catch (NumberFormatException nfe)
{
JOptionPane.showMessageDialog(null,"That is not an integer, enter height again");
}
} while(num < 0);
Sone.setHeight(num);
}
else if(change1.equalsIgnoreCase("n"))
{
System.exit(0);
}
if (change2.equalsIgnoreCase("y"))
{
do
{
String input = JOptionPane.showInputDialog("Enter Radius of Silo:2");
try
{
num = Double.parseDouble(input);
}
catch (NumberFormatException nfe)
{
JOptionPane.showMessageDialog(null,"That is not an integer, enter radius again");
}
} while(num < 0);
Stwo.setRadius(num);
do
{
String input = JOptionPane.showInputDialog("Enter Height of Silo:2");
try
{
num = Double.parseDouble(input);
}
catch (NumberFormatException nfe)
{
JOptionPane.showMessageDialog(null,"That is not an integer, enter height again");
}
} while(num < 0);
Stwo.setHeight(num);
}
else if(change2.equalsIgnoreCase("n"))
{
System.exit(0);
}
if (change1.equalsIgnoreCase("y"))
{
JOptionPane.showMessageDialog(null,"Silo 1 Dimensions:\n" + "Radius = " + fmt.format(Sone.getRadius()) +"\nHeight = " + fmt.format(Sone.getHeight()) + "\nVolume = " + fmt.format(Sone.getVolume()) + "\nSurface Area = " + fmt.format(Sone.getSurfaceArea()));
}
if (change2.equalsIgnoreCase("y"))
{
JOptionPane.showMessageDialog(null,"Silo 2 Dimensions:\n" + "Radius = " + fmt.format(Stwo.getRadius()) +"\nHeight = " + fmt.format(Stwo.getHeight()) + "\nVolume = " + fmt.format(Stwo.getVolume()) + "\nSurface Area = " + fmt.format(Stwo.getSurfaceArea()));
}
}
}