public class Demo{
public static void main(String[] args){
Rectangle re=new Rectangle();
re.seta(2.5);
re.setb(2.8);
re.comput();
Circle ci=new Circle();
ci.seta(2.5);
ci.setb(3.5);
ci.comput();
}
}
abstract class Shapc{
private double a;
private double b;
public double geta(){
return a;
}
public void seta(double a){
this.a=a;
}
public double getb(){
return b;
}
public void setb(double b){
this.b=b;
}
public abstract void comput();
}
class Rectangle extends Shapc{
public void comput(){
double rectArea=geta()*getb();
double rectPerimeter=(geta()+getb())*2;
System.out.println("矩形的周长:"+rectPerimeter+",矩形的面积:"+rectArea);
}
}
class Circle extends Shapc{
public void comput(){
double cirArea=geta()*getb()*getb();
double cirPerimeter=geta()*getb()*2;
System.out.println("圆形的周长:"+cirPerimeter+",圆形的面积:"+cirArea);
}
}
mtexiy_Sss
相关分类