//Quadratic.java import java.awt.*; import javax.swing.*; public class Quadratic extends JApplet { public void init() { double a, b, c, discriminant, x1, x2; String input; input = JOptionPane.showInputDialog("Enter a"); a = Double.parseDouble(input); input = JOptionPane.showInputDialog("Enter b"); b = Double.parseDouble(input); input = JOptionPane.showInputDialog("Enter c"); c = Double.parseDouble(input); discriminant = b*b - 4*a*c; if (a == 0) JOptionPane.showMessageDialog(null, "a can not be 0"); else if (discriminant > 0) { // calculate the two possible real values for x. x1 = (-b + Math.sqrt(discriminant)) / (2 * a); x2 = (-b - Math.sqrt(discriminant)) / (2 * a); JOptionPane.showMessageDialog(null, "x1="+x1+" x2="+x2); } else if (discriminant == 0) { //one real root x1 = -b / (2*a); JOptionPane.showMessageDialog(null, "x="+x1); } else //no real roots JOptionPane.showMessageDialog(null, "Discriminant is negative"); } }