0
如果有人能帮忙,我无法弄清楚我的代码有什么问题,为什么它告诉我这些?它给我一个toString方法的错误...为什么它给我插入枚举正文和标识符?谢谢语法错误,在java中插入“EnumBody”和“枚举标识符”
import java.lang.String;
public class Circle extends Shape {
private double radius;
public Circle(double theRadius){
super();
if (theRadius <= 0.0)
setRadius(Shape.DEFAULT_SIZE);
else
setRadius(theRadius);
}
public double getSurfaceArea(){
return this.radius * this.radius * Math.PI;
}
public double getPeremeter(){
;
return 2 * this.radius + Math.PI;
}
public double getRadius(){
return this.radius;
}
public void setRadius(double theRadius) {
if(theRadius <= 0)
return;
this.radius = theRadius;
}
@Override
public double getPerimeter() {
// TODO Auto-generated method stub
return 0;
public String toString() {
return "Circle Surface Area "+getSurfaceArea()+", Circle Peremeter " +getPerimeter();
}
}
@Override
public double getSizeAmount() {
// TODO Auto-generated method stub
return 0;
}
}
主类
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class ShapeApp {
public static <RectangularPrism> void main(String[] args) {
int x = 0;
Triangle triangleObjects[] = new Triangle[ 3 ];
triangleObjects[ 0 ] = new Rectangle("3.5","4.6");
triangleObjects[ 1 ] = new Rectangle("3","2");
triangleObjects[ 2 ] = new Circle(0);
System.out.println("List of all Shapes:\n");
do{
try{
for(Triangle currentTriangle : triangleObjects) {
String msg = currentTriangle.getSurfaceArea() +","+ currentTriangle.getPerimeter();
JOptionPane.showMessageDialog(null, "Message", msg, JOptionPane.INFORMATION_MESSAGE);
x=2;
}
}catch(Exception e) {
}
}while(x==1);
}
}
错误
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "String", @ expected
Syntax error, insert "enum Identifier" to complete EnumHeaderName
Syntax error, insert "EnumBody" to complete BlockStatement
at Circle.getPerimeter(Circle.java:44)
at ShapeApp.main(ShapeApp.java:80)
是什么类形是什么样子?并且在Circle类中缺少getPerimeter()的括号,不确定是否会导致所有错误? – centic