I have the below code and I needed to add a try catch to insure proper data, the below doesn't work at all. It prompts for the blower value but if I type in an improper value it still will not "catch" the error? Please help if possible I am very new to java.
String test = " ";
boolean badInput = true;
if(race.getClass()== Hotrod.class)
{
Hotrod h =(Hotrod)race;
//test = (getInput("Blower equipped: Y/N"));
if (test.equalsIgnoreCase("y"))
{
h.setBlower(true);
}// end if
else if (test.equalsIgnoreCase("n"))
{
h.setBlower(false);
} //end else if
else
{
do{
try
{
test = (getInput("Blower equipped: Y/N"));
if (!test.equalsIgnoreCase("y")|| !test.equalsIgnoreCase("n"))
{
badInput = false;
}
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null,test + "Please enter the proper value","Error",JOptionPane.PLAIN_MESSAGE);
}
} while(badInput);
}//end else
} //end if(race.getClass()== Hotrod.class)
ASKER