Import the Java. Text. DecimalFormat;
The import static Java. Lang. Math. PI;
The class Shape {
Public double area () {
return 0;
}
Public double girth () {
return 0;
}
}
The class Circle extends Shape {//round
Private double r;
Public Circle (double r) {
This. R=r;
}
Public double area () {//rewrite
return PI*r*r;
}
Public double girth () {//rewrite
Return 2 * r * PI;
}
}
Class a Rectangle extends Shape {//Rectangle
Double chang;
Double kuan.
Public Rectangle (double chang, double kuan) {
This. Chang=chang;
This. Kuan=kuan;
}
Public double area () {//rewrite
Return kuan chang *;
}
Public double girth () {//rewrite
Return 2 * (+ kuan chang);
}
}
The class Square extends Shape {//Square
Private double bianchang;
Public Square (double bianchang) {
Enclosing bianchang=bianchang;
}
Public double area () {//rewrite
Return bianchang * bianchang;
}
Public double girth () {//rewrite
Return 4 * bianchang;
}
}
Public class Testshape {
Public static void main (String ares []) {
Circle Circle=new Circle (10);
A Rectangle the rect=new Rectangle (10, 29).
Square Square=new Square (5);
DecimalFormat sd=new DecimalFormat (" 0.0 ");
System. The out. Println (" circular area is: "+ sd. The format (circle) area ()));
System. The out. Println (" is the perimeter of a circle is: "+ sd. The format (circle) girth ()));
System. The out. Println (" is the area of the rectangle is: "+ the rect. Area ());
System. The out. Println (" is the perimeter of rectangle is: "+ the rect. Girth ());
System. The out. Println (" is the area of the square is: "+ square. Area ());
System. The out. Println (" is the perimeter of the square is: "+ square. Girth ());
}
}