interface ShowShape{
public void print();
}
abstract class MyShape implements ShowShape{
public abstract double mianji();
public abstract double zhouchang();
}
class MyCircle extends MyShape{
private double radius;
public static final double PI=3.1415926;
public void setRadius(double radius){
this.radius=radius;
}
public double mianji(){
return this.radius*this.radius*PI;
}
public double zhouchang(){
return this.radius*2*PI;
}
public double getRadius(){
return this.radius;
}
public void print(){
System.out.println("半径为"+getRadius()+"的圆形面积为: "+mianji()+",周长为 :"+zhouchang());
}
}
class MyRectangle extends MyShape{
private double length;
private double width;
public void setLength(double length){
this.length=length;
}
public void setWidth(double width){
this.width=width;
}
public double getLength(){
return this.length;
}
public double getWidth(){
return this.width;
}
public double mianji(){
return this.length*this.width;
}
public double zhouchang(){
return 2*(this.length+this.width);
}
public void print(){
System.out.println("长为:"+getLength()+",宽为 :"+getWidth()+"的钜形面积为: "+mianji()+",周长为 :"+zhouchang());
}
}
public class TestMyShape {
public static void main(String args[]){
MyCircle circle=new MyCircle();
circle.setRadius(10);
circle.print();
MyRectangle retangle=new MyRectangle();
retangle.setLength(10);
retangle.setWidth(5);
retangle.print();
}
}