La clase no es abstracta y no anula el error método abstracto

Steven:

He estado trabajando en un programa que se puede encontrar la raíz de un polinomio para la escuela, y hacer varias otras cosas relacionadas polinomio como sumándolos o encontrar el valor de un polinomio con un determinado x. Mientras que las otras dos clases que hacen bien el trabajo (que encuentran la raíz de una función seno y coseno), mi clase FuncPoly parece estar en conflicto con mi método de evaluar de alguna manera, y no quiere que la posea. Este es mi mensaje de error exacto:

. \ FuncPoly.java: 1: Error: FuncPoly no es abstracta y no anula método abstracto evaluar (doble) en la clase pública se extiende FuncPoly Función Función {

He intentado tocar el violín con el método de evaluar un poco y tratando de añadir algunas sustituciones en, pero no me ha estado ayudando mucho. Necesito ayuda para encontrar lo que está causando este error; tal vez su relación con mi constructor ?. Gracias por la lectura y su ayuda! Código está por debajo; hay una gran cantidad de allí, pero no creo que la mayor parte es pertinente para la cuestión.


    public abstract double evaluate(double x); //Basically just a filler for SinFunc and CosFunc

    public double findRoot(double a, double b, double epsilon){

        double x = ( a + b ) / 2;

        if (Math.abs( a - x) <= epsilon){

            return x;

        }else if (evaluate(x)*evaluate(a) >= 0){

            return findRoot(x, b, epsilon);

        }else{

            return findRoot(a, x, epsilon);
        }
    }

    public static void main(String[] args){
        //Tests SinFunc and CosFunc
        SinFunc q = new SinFunc();
        CosFunc w = new CosFunc();
        System.out.println("The root of sin(x) with the numbers entered with the given epsilon is: " + q.findRoot(3,4,.00000001));
        System.out.println("The root of cos(x) with the numbers entered with the given epsilon is: " + w.findRoot(1,3,.00000001));

        //Tests the FuncPoly stuff
        int[] test1 = {1,0,-3};
        int[] test2 = {1,-1,-2};
        FuncPoly poly1 = new FuncPoly(test1);
        FuncPoly poly2 = new FuncPoly(test2);
        System.out.println("The root of x^2 + (-3) is" + poly1.findRoot(0,10,.00000001));

    }
}

____________________________

public class FuncPoly extends Function{

    public int coefficients[];

    public FuncPoly(int[] coefficients){
        //Constructor
        this.coefficients = coefficients;
    }

    public int degree(){
        //Finds the highest power by finding the location of the last number in the array.
        return this.coefficients.length - 1;

    }

    public String toString(){
        //Converts a polynomial to a string
        StringBuilder poly = new StringBuilder();
        for(int i = degree(); i >= 0; i--){
            if (i == degree()){
                poly.append(this.coefficients[i] + "x^" + degree());
            }else{
                if (this.coefficients[i] == 0){
                    System.out.println(i);
                }else if (i == 0){
                    poly.append(" + " + this.coefficients[0]);
                } else if ( i == 1){
                    poly.append(" + " + this.coefficients[1] + "x");
                } else{
                    poly.append(" + " + this.coefficients[i] + "x^" + i);
                }
            }
        }

        return poly.toString();
    }

    public FuncPoly add(FuncPoly a){
        //Adds the selected polynomial and the last called polynomial together and returns the array.
        if (this.degree() > a.degree()){
            int[] polyAdd = new int[this.degree() + 1];
            for (int i = 0; i <= a.degree(); i++){
                polyAdd[i] = a.coefficients[i] + this.coefficients[i];
            }
            for (int i = a.degree() + 1; i < this.degree() + 1; i++){
                polyAdd[i] = this.coefficients[i];
            }
            FuncPoly polyResult = new FuncPoly(polyAdd);
            return polyResult;
        } else if (this.degree() < a.degree()){
            int[] polyAdd = new int[a.degree() + 1];
            for (int i = 0; i <= this.degree(); i++){
                polyAdd[i] = a.coefficients[i] + this.coefficients[i];
            }
            for (int i = this.degree() + 1; i < degree() + 1; i++){
                polyAdd[i] = a.coefficients[i];
            }
            FuncPoly polyResult = new FuncPoly(polyAdd);
            return polyResult;
        } else {
            int[] polyAdd = new int[a.degree() + 1];
            for (int i = 0; i < a.degree() + 1; i++){
                polyAdd[i] = a.coefficients[i] + this.coefficients[i];
            }
            FuncPoly polyResult = new FuncPoly(polyAdd);
            return polyResult;
        }
    }

    public double value(double x){
        //Finds the value of polynomial with a given x.
        double sum = 0;
        for(int i = 0; i < this.degree() + 1; i++){
            sum += this.coefficients[i] * Math.pow(x,i);
        }
        return sum;
    }

}
Robby Cornelissen:

Por lo que yo puedo decir, el value()método de FuncPolylas necesidades que se cambió el nombre a evaluate()implementar con éxito el resumen evaluate()método de la Functionclase.

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=333004&siteId=1
Recomendado
Clasificación