mercredi 3 mai 2017

How do I run the wrong input, try again line?

For the if (inputMass.equalsIgnoreCase(poundQ) code block, I am unable to find a way to run the Wrong input, try again line if I enter any string besides a double. Any help would be extremely appreciated!!!

 if (inputMass.equalsIgnoreCase(poundQ) || inputMass.equalsIgnoreCase(lbQ)) {

                        String lbs1 = JOptionPane.showInputDialog(null, "What is the number of pounds?", "Enter Info", JOptionPane.QUESTION_MESSAGE);

                        double lbs = Double.parseDouble(lbs1);

                          if(lbs != Double.parseDouble(lbs1)) {
                              JOptionPane.showMessageDialog(null, "Wrong input try again.", "Error", JOptionPane.WARNING_MESSAGE);
                          }

                            JOptionPane.showMessageDialog(null, lbs + " lb equal to " + df.format(lbs * 0.005) + " oz."
                                + "\n" + lbs + " lb equal to " + df.format(lbs * 0.0005) + " ton."
                                + "\n" + lbs + " lb equal to " + df.format(lbs * 0.45359237) + " kg."
                                + "\n" + lbs + " lb equal to " + df.format(lbs * 453.59237) + " g."
                                + "\n" + lbs + " lb equal to " + df.format(lbs * 45359.237) + " cg."
                                + "\n" + lbs + " lb equal to " + df.format(lbs * 453592.37) + " mg.",
                                "Result", JOptionPane.INFORMATION_MESSAGE);
                    } 

Aucun commentaire:

Enregistrer un commentaire