/** *A class that solves the quadratic equation. */public class QuadraticEquation{ /** * Constructs an equation with input values for a, b, and c. * @param a The coefficient A in the quadratic equation. * @param b The coefficient B in the quadratic equation. * @param c The number C in the quadratic equation. */ public QuadraticEquation(double a, double b, double c) { solution1 = (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a); solution2 = (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a); discriminant = Math.pow(b, 2) - 4 * a * c; } /** * A method that returns 1 possible solution to the quadratic equation, * such that return value is less than or equal to the value of method getSolution2(). * If no solutions exist, the value 0 is returned. */ public double getSolution1() { if (solution1 != 0 && solution1 < solution2) return solution1; if (solution1 >= solution2) return solution2; else return 0; } /** * A method which returns a possible solution to the quadratic equation, * such that the return value is greater than or equal to the value of method getSolution1(). * If no solutions exist, the value 0 is returned. */ public double getSolution2() { if (solution2 != 0 && solution2 > solution1) return solution2; if (solution2 <= solution1) return solution1; else return 0; } /** * A boolean method which returns true if the quadratic equation has solutions, * and returns false if the equation does not have solutions. */ public boolean hasSolutions() { if ( 0 > discriminant) return false; else return true; } private double solution1; private double solution2; private double discriminant;}