【发布时间】:2013-01-03 23:08:26
【问题描述】:
我已经完成了这个尝试构建三角形并计算家庭作业表面的小程序,我在 Eclipse 中对其进行了测试,但是当我尝试将其上传到我们的系统时,我得到了 6 个错误,所有错误类型都相同:
/test/src/math.test/TestTriangleFunctionPublic.java:4:错误:找不到符号 导入数学.NotATriangleException; ^ 符号:类 NotATriangleException
/test/src/math.test/TestTriangleFunctionPublic.java:5:错误:找不到符号 导入数学。三角形; ^ 符号:三角形类 位置:数学包
/test/src/math.test/TestTriangleFunctionPublic.java:45:错误:找不到符号 实际 = Triangle.calculateArea(a, b, c); ^ 符号:可变三角形 位置:类TestTriangleFunctionPublic
/test/src/math.test/TestTriangleFunctionPublic.java:46:错误:找不到符号 } 捕捉(NotATriangleException e1){ ^ 符号:类 NotATriangleException 位置:类TestTriangleFunctionPublic
/test/src/math.test/TestTriangleFunctionPublic.java:56:错误:找不到符号 实际 = Triangle.calculateArea(a, b, c); ^ 符号:可变三角形 位置:类TestTriangleFunctionPublic
/test/src/math.test/TestTriangleFunctionPublic.java:57:错误:找不到符号 } 捕捉(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);
}
}
我很失望,因为我不知道出了什么问题!
【问题讨论】:
-
向我们展示 TestTriangleFunctionPublic 类。
-
问题似乎出在“TestTriangleFunctionPublic.java”中,但代码不在post中?!?