我一直在開(kāi)發(fā)一個(gè)程序,可以為學(xué)校找到多項(xiàng)式的根,并執(zhí)行各種其他多項(xiàng)式相關(guān)的操作,例如將它們加在一起或查找給定 x 的多項(xiàng)式的值。雖然我制作的其他兩個(gè)類工作正常(它們找到了 sin 和 cos 函數(shù)的根),但我的 FuncPoly 類似乎與我的評(píng)估方法以某種方式發(fā)生沖突,并且不想繼承它。這是我的確切錯(cuò)誤消息:.\FuncPoly.java:1: 錯(cuò)誤:FuncPoly 不是抽象的,并且不會(huì)重寫(xiě) Function public class FuncPoly extends Function{ 中的抽象方法評(píng)估(double)我嘗試稍微擺弄評(píng)估方法并嘗試添加一些覆蓋,但它對(duì)我沒(méi)有多大幫助。我需要幫助找出導(dǎo)致此錯(cuò)誤的原因;也許它與我的構(gòu)造函數(shù)有關(guān)?感謝您的閱讀和幫助!代碼如下;里面有很多內(nèi)容,但我認(rèn)為其中大部分與問(wèn)題無(wú)關(guā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; }
類不是抽象的,并且不重寫(xiě)抽象方法錯(cuò)誤
滄海一幻覺(jué)
2023-08-04 15:52:52