My returning values are not coming up as right, and I'm just wondering what I am doing wrong, my code looks fine?!
some of the test that are coming up are:
Test failed: expected was not equal to actual
Expected = 9.000000 and actual = 0.000000
The discriminant is not being computed correctly
Test failed: expected was not equal to actual
Expected = -3.000000 and actual = 0.000000
public class QuadraticEquation {
//coefficients
private double a;
private double b;
private double c;
// created a discriminant instance variable so it's easier to access
// rather than tying out "Math.pow(b, 2) - 4 * a * c" every time
// the discriminant is required
private double discriminant = Math.pow(b, 2) - (4 * a * c);
//constructor
public QuadraticEquation(double a, double b, double c) {
this.a = a;
this.b = b;
this.c = c;
}
//getter for A
public double getA() {
return a;
}
//getter for B
public double getB() {
return b;
}
//getter for C
public double getC() {
return c;
}
// get discriminant
// the discriminant is inside of the square root,
// and b^2 - 4ac is the expression for the discriminant
public double getDiscriminant() {
//b^2 - 4ac
return discriminant;
}
//get root0
public double getRoot0(){
if (discriminant > 0) {
return -b + Math.sqrt(discriminant) / 2*a;
}
return Double.NaN;
}
public double getRoot1() {
if (discriminant > 0) {
return -b - Math.sqrt(discriminant) / 2*a;
}
return Double.NaN;
}
}