我一直在開發一個程序,可以為學校找到多項式的根,并執行各種其他多項式相關的操作,例如將它們加在一起或查找給定 x 的多項式的值。雖然我制作的其他兩個類工作正常(它們找到了 sin 和 cos 函數的根),但我的 FuncPoly 類似乎與我的評估方法以某種方式發生沖突,并且不想繼承它。這是我的確切錯誤消息:.\FuncPoly.java:1: 錯誤:FuncPoly 不是抽象的,并且不會重寫 Function public class FuncPoly extends Function{ 中的抽象方法評估(double)我嘗試稍微擺弄評估方法并嘗試添加一些覆蓋,但它對我沒有多大幫助。我需要幫助找出導致此錯誤的原因;也許它與我的構造函數有關?感謝您的閱讀和幫助!代碼如下;里面有很多內容,但我認為其中大部分與問題無關。 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; }
添加回答
舉報
0/150
提交
取消