// This class represents a quadratic equation of the form: a*x^2 + b*x + c = 0. With this class, you can solve for x ore determine that there is no solution. public class QuadraticEquation { private int a, b, c; // the three coefficients, we make the assumption that we will only use integer coefficients public QuadraticEquation(int newa, int newb, int newc) { a=newa; // assign all 3 coefficients b=newb; c=newc; } // accessor methods for the three instance data public int getA() {return a;} public int getB() {return b;} public int getC() {return c;} // mutator (setter) methods for all three instance data public void setA(int newa) {a=newa;} public void setB(int newb) {b=newb;} public void setC(int newc) {c=newc;} // compute the discriminant which is b^2 - 4ac public int getDiscriminant() { return b*b-4*a*c; } // If the discriminant is positive, there are two roots as computed by getRoot1 and getRoot2. If the discriminant is 0, then there is a one root which both // getRoot1 and getRoot2 will return. If the discriminant is negative, there are no roots and both methods return 0. We might modify this to return // a number that is clearly erroneous like -999999 or throw an Exception public double getRoot1() { int discriminant=getDiscriminant(); if(discriminant>=0) return (-1.0*b+Math.sqrt(discriminant))/(2.0*a); else return 0; } public double getRoot2() { int discriminant=getDiscriminant(); if(discriminant>=0) return (-1.0*b-Math.sqrt(discriminant))/(2.0*a); else return 0; } }