Here's my code:
public abstract class Function{
public abstract double evaluate(double x);
public double findRoot(double a, double b, double epsilon){
if( (evaluate(a) > 0 && evaluate(b) > 0) || (evaluate(a) < 0 && evaluate(b) < 0)){
System.out.println("There is no root between these two points.");
}
double x = (a+b)/2;
if(Math.abs(a-x) < epsilon){
return x;
}
else if((evaluate(x) < 0 && evaluate(a) < 0) || (evaluate(x) > 0 && evaluate(a) > 0)){
return findRoot(x, b, epsilon);
}
else{
return findRoot(a, x, epsilon);
}
}
public static void main(String[] args){
double testSinFunc = SinFunc.findRoot(3, 4, .01);
double testCosFunc = CosFunc.findRoot(1, 2, .01);
if(testSinFunc == 3.14){
System.out.println("SinFunc.findRoot(3, 4, .01) returned 3.14. Test passed!");
}
if(testCosFunc == 1.57){
System.out.println("CosFunc.findRoot(1, 2, .01) returned 1.57. Test passed!");
}
}
}
The compiler says :
non-static method findRoot(double, double, double) cannot be referenced from a static context
What would I do to fix this?