Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. //Method for my team by Leyca Besarra, Paul Davis and Ibrahim Alshubaily
  2.  
  3. //This method is for processing userInput for coefficients a, b, and c of the quadratic equation via JOptionPane
  4. //this is meant to be used with doubles.
  5. //this needs 'import javax.swing.JOptionPane;'
  6. //the method should be used similarly to the lines below, but for the 3 coefficients.
  7. //double a = inHandler("For the equation, Ax^2+Bx+C = 0, please enter the coefficient A");
  8. //double b = inHandler("For the equation, Ax^2+Bx+C = 0, please enter the coefficient B");
  9. //double c = inHandler("For the equation, Ax^2+Bx+C = 0, please enter the coefficient C");
  10. //make the variable(some sorts of doubles) invoke the method name inHandler, and place the desired message to be shown to the user within (" ")
  11.  
  12.  
  13.     public static double inHandler(String prompt){
  14.         double returnValue = 0;
  15.         boolean tryAgain = false;
  16.         do {
  17.             String s = JOptionPane.showInputDialog(prompt);
  18.             try {
  19.                 returnValue = Double.parseDouble(s);
  20.             } catch (NumberFormatException e){
  21.                 returnValue = Double.NaN;
  22.                 if (Double.isNaN(returnValue)){
  23.                     JOptionPane.showMessageDialog(null, "you have entered something I can't understand, please try again.");
  24.                 }
  25.                 tryAgain = true;
  26.             }
  27.         } while (tryAgain);
  28.         return returnValue;
  29.     } //end of inHandler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement