All pastes #2063962 Raw Edit

Unnamed

public text v1 · immutable
#2063962 ·published 2011-05-18 23:59 UTC
rendered paste body
    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package question2;
import javax.swing.JOptionPane;
/**
 *
 * @author crusoe
 */
public class Question2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        String      numA, numB, numC;
        double         a, b, c, x1, x2, numer, denom;
        
        numA = JOptionPane.showInputDialog("Enter a double for A");
        numB = JOptionPane.showInputDialog("Enter a double for B");
        numC = JOptionPane.showInputDialog("Enter and double for C");
        
        a = Double.parseDouble (numA);
        b = Double.parseDouble (numB);
        c = Double.parseDouble (numC);
        
        numer = (Math.sqrt(Math.pow((b), 2) - (4*a*c)));
        denom = (2*a);
        
        x1 = ((- b) + numer) / (denom);
        x2 = ((- b) - numer) / (denom);
        
        if (Double.isNaN(numer))
            {
                JOptionPane.showMessageDialog(null, "Equation has no roots");
            }
        if (numer > 0)
            {
                JOptionPane.showMessageDialog(null, "Equation has two roots: " + x1 + " and " + x2);
            }
        if (numer == 0)
            {
                JOptionPane.showMessageDialog(null, "Equation has one root: " + x1);
            }
        if (numer < 0)
            {
                JOptionPane.showMessageDialog(null, "Equation has imaginary roots");
            }
        
    }
}