2

我已经完成了这个尝试构建三角形并计算作业表面的小程序,并在 Eclipse 中对其进行了测试,但是当我尝试将其上传到我们的系统时,我得到了 6 个错误,都是相同的类型:

/test/src/math.test/TestTriangleFunctionPublic.java:4:错误:找不到符号导入math.NotATriangleException;^ 符号:类 NotATriangleException

/test/src/math.test/TestTriangleFunctionPublic.java:5:错误:找不到符号导入math.Triangle;^ 符号:类三角形位置:包数学

/test/src/math.test/TestTriangleFunctionPublic.java:45:错误:找不到符号实际= Triangle.calculateArea(a,b,c);^ 符号:变量三角形位置:类 TestTriangleFunctionPublic

/test/src/math.test/TestTriangleFunctionPublic.java:46:错误:找不到符号} catch (NotATriangleException e1) { ^ 符号:类 NotATriangleException 位置:类 TestTriangleFunctionPublic

/test/src/math.test/TestTriangleFunctionPublic.java:56:错误:找不到实际符号 = Triangle.calculateArea(a, b, c); ^ 符号:变量三角形位置:类 TestTriangleFunctionPublic

/test/src/math.test/TestTriangleFunctionPublic.java:57:错误:找不到符号} catch (NotATriangleException e) { ^ 符号:类 NotATriangleException 位置:类 TestTriangleFunctionPublic

这是两个类:

package math;

public class Triangle {
    static double s;
    double surface = 0;
    static double a;
    static double b;
    static double c;

    public double calculateArea(double a, double b, double c) throws NotATriangleException{
        if (a<= 0.0 || b <= 0.0 || c <= 0.0){
            throw new NotATriangleException("Cannot construct Triangle!");
        }
        else if( (a+b)<=c && (a+c)<=b && (b+c)<=a){
            throw new NotATriangleException("Cannot construct Triangle!"); 
        } 

        else {
            s = ((a + b + c)/2);
            surface = Math.sqrt(s * (s - a) * (s - b) * (s - c));
            return surface;
        }

    }
    public double getErgebnis (){
        return surface;
    }
}

和异常类:

package math;

@SuppressWarnings("serial")
public class NotATriangleException extends Exception {
    public NotATriangleException(String message) {
        super(message);
    }
    public NotATriangleException(String message,Throwable throwable) {
        super(message, throwable);
    }
}

我很失望,因为我不知道出了什么问题!

4

1 回答 1

2

你有一个名为TestTriangleFunctionPublic. 我想你在 Eclipse 的同一个包中拥有这个类math,但是当你上传它时,你将位置更改为一个名为 math.test 的目录。

于 2013-01-20T21:31:39.107 回答