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)
Programming Languages-OtherJava

Avatar of undefined
Last Comment
steven
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of steven
steven
Flag of United States of America image

ASKER

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

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo