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)
答案 0 :(得分:2)
查看您的getPerimeter
方法:
@Override
public double getPerimeter() {
// TODO Auto-generated method stub
return 0;
public String toString() {
return "Circle Surface Area "+getSurfaceArea()+", Circle Peremeter "
+getPerimeter();
}
}
您尝试在 toString
方法中声明getPerimeter
方法。
代码的缩进应该给你一个暗示 - 这是为什么适当地缩进代码很重要的一个原因。你应该:
@Override
public double getPerimeter() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String toString() {
return "Circle Surface Area " + getSurfaceArea() + ", Circle Perimeter "
+ getPerimeter();
}
答案 1 :(得分:0)
@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 getPerimeter() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String toString() {
return "Circle Surface Area "+getSurfaceArea()+", Circle Peremeter " +getPerimeter();
}