Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Method for my team by Leyca Besarra, Paul Davis and Ibrahim Alshubaily
- //This method is for processing userInput for coefficients a, b, and c of the quadratic equation via JOptionPane
- //this is meant to be used with doubles.
- //this needs 'import javax.swing.JOptionPane;'
- //the method should be used similarly to the lines below, but for the 3 coefficients.
- //double a = inHandler("For the equation, Ax^2+Bx+C = 0, please enter the coefficient A");
- //double b = inHandler("For the equation, Ax^2+Bx+C = 0, please enter the coefficient B");
- //double c = inHandler("For the equation, Ax^2+Bx+C = 0, please enter the coefficient C");
- //make the variable(some sorts of doubles) invoke the method name inHandler, and place the desired message to be shown to the user within (" ")
- public static double inHandler(String prompt){
- double returnValue = 0;
- boolean tryAgain = false;
- do {
- String s = JOptionPane.showInputDialog(prompt);
- try {
- returnValue = Double.parseDouble(s);
- } catch (NumberFormatException e){
- returnValue = Double.NaN;
- if (Double.isNaN(returnValue)){
- JOptionPane.showMessageDialog(null, "you have entered something I can't understand, please try again.");
- }
- tryAgain = true;
- }
- } while (tryAgain);
- return returnValue;
- } //end of inHandler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement