public class QuadraticEquation { // a quadratic equation a*x^2 + b*x + c = 0 double a; double b; double c; /* QuadraticEquation() { }*/ QuadraticEquation(double a1, double b1, double c1) { // create a new quadratic equation with the given coefficients a = a1; b = b1; c = c1; } private String toSignedString(double d) { // creates string from double value with explicit sign if (d >= 0) { return("+ " + d); } else { return("- " + (-d)); } } private double discriminant() { // the discriminant of the equation return(b*b/(4*a*a) - c/a); } double[] getSolution() { // returns vector of solution values double a1,d,dRoot,result[]; a1 = -b/(2*a); d = discriminant(); if (d > 0) { result = new double[2]; dRoot = Math.sqrt(d); result[0] = a1 + dRoot; result[1] = a1 - dRoot; } else if (d == 0) { result = new double[1]; result[0] = a1; } else { // d<0: result is empty result = new double[0]; } return(result); } void print1() { // print the equation to the screen // System.out.println(a + "*x^2 + "+ b + "*x + " + c); System.out.println(a + "*x^2 "+ toSignedString(b) + "*x " + toSignedString(c)); } void print2() { // print this to the screen System.out.println("it works !"); } static void print3() { // print this to the screen System.out.println("Yes it really works !"); } }