Link to home
Start Free TrialLog in
Avatar of steven
stevenFlag for United States of America

asked on

I have a java code that is not preforming what i expect to, i am very new to java.

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 CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of steven

ASKER

I understand I will alter the code maybe with do while loop?