abstract class Shapetwo{
public abstract void area();
public abstract void perimeter();
}
class Ju extends Shapetwo{
float length;
float width;
public Ju(float length,float width){
this.length=length;
this.width=width;
}
public void area(){
System.out.println("矩形的面积为:"+length*width);
}
public void perimeter(){
System.out.println("矩形的周长为:"+2*(length+width));
}
}
class San extends Shapetwo{
float di;
float gao;
float b1;
float b2;
float b3;
public San(float b1,float b2,float b3,float di,float gao){
this.di=di;
this.gao=gao;
this.b1=b1;
this.b2=b2;
this.b3=b3;
}
public void area(){
System.out.println("三角形的面积为:"+(di*gao/2));
}
public void perimeter(){
System.out.println("三角形的周长为:"+(b1+b2+b3));
}
}
public class t65 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Ju j=new Ju(20,20);
j.area();
j.perimeter();
San s=new San(3,4,5,3,4);
s.area();
s.perimeter();
}
}
面积和周长
最新推荐文章于 2022-02-27 13:03:16 发布