我已经完成了这个小程序,试图构建三角形并计算作业的表面,我在Eclipse中测试它但是当我尝试将它上传到我们的系统时,我得到6个错误,所有相同的类型:
/test/src/math.test/TestTriangleFunctionPublic.java:4:错误:找不到符号 import math.NotATriangleException; ^ symbol:class NotATriangleException
/test/src/math.test/TestTriangleFunctionPublic.java:5:错误:找不到符号 import math.Triangle; ^ 符号:类三角形 location:包数学
/test/src/math.test/TestTriangleFunctionPublic.java:45:错误:找不到符号 actual = Triangle.calculateArea(a,b,c); ^ 符号:变量三角形 location:类TestTriangleFunctionPublic
/test/src/math.test/TestTriangleFunctionPublic.java:46:错误:找不到符号 } catch(NotATriangleException e1){ ^ symbol:类NotATriangleException location:类TestTriangleFunctionPublic
/test/src/math.test/TestTriangleFunctionPublic.java:56:错误:找不到符号 actual = Triangle.calculateArea(a,b,c); ^ 符号:变量三角形 location:类TestTriangleFunctionPublic
/test/src/math.test/TestTriangleFunctionPublic.java:57:错误:找不到符号 } catch(NotATriangleException e){ ^ symbol:类NotATriangleException location:类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;
}
}
和Exception类:
package math;
@SuppressWarnings("serial")
public class NotATriangleException extends Exception {
public NotATriangleException(String message) {
super(message);
}
public NotATriangleException(String message,Throwable throwable) {
super(message, throwable);
}
}
我很失望,因为我无法弄清楚出了什么问题!
答案 0 :(得分:2)
您有一个名为TestTriangleFunctionPublic
的班级。我认为你在Eclipse的同一个math
包中有这个类,但是当你上传它时,你将位置更改为一个名为math.test的目录。