📄 area.java
字号:
import java.lang.Math
public class Area{ //定义了类Area_cir,作为外部类
float l,s;
public abstract class abc{ //定义了接口abc
public abstract float cir();
public abstract float area();
public abstract void output();
}
public class Zhix extends abc{ //定义了内部类Zhix,求解直线的周长和面积
float x1,x2,y1,y2;
public Zhix(float x,float y,float z,float w){
x1=x;
x2=y;
y1=z;
y2=w;
}
public float cir(){
double d=(x1-x2)*(x1-x2);
double e=(y1-y2)*(y1-y2);
float l=Math.sqrt(d+e);
return l;}
public float area(){
s=-1;
return s;
}
public void output(){
System.out.println("the circle of the zhixian is:"+this.cir());
System.out.println("the area of the zhixian is :"+this.area());
}
}
public class Sanjx extends abc { //定义了内部类Sanjx,求解三角形的周长和面积
float a,b,c,u;
public Sanjx(float x,float y,float z){
a=x;
b=y;
c=z;
}
public float cir(){
l=a+b+c;
return l;}
public float area(){
u=l/2;
double k=u*(u-a)*(u-b)*(u-c);
float s=Math.sqrt(k);
return s;
}
public void output(){
System.out.println("the circle of the sanjx is:"+this.cir());
System.out.println("the area of the sanjx is:"+this.area()); }
}
public class Jux extends abc{ //定义了内部类Jux,求解矩形的周长和面积
float m,n;
public Jux(float x,float y){
m=x;
n=y;
}
public float cir(){
l=(m+n)*2;
return l;
}
public float area(){
s=m*n;
return s;
}
public void output(){
System.out.println("the circle of the juxing is:"+this.cir());
System.out.println("the area of the juxing is:"+this.area()); }
}
public class Yuanx extends abc{ //定义了内部类Yuanx,求解圆形的周长和面积
float r;
final float PI=3.14;
public Yuanx(float x){
r=x;
}
public float cir(){
l=2*PI*r;
return l;}
public float area(){
s=PI*r*r;
return s;
}
public void output(){
System.out.println("the circle of the yuanxing is:"+this.cir());
System.out.println("the area is of the yuanxing:"+this.area()); }
}
public Area(){
Zhix a4=new Zhix(3,6,9,12); //生成直线对象
a4.output();
Sanjx a1=new Sanjx(6,8,10); //生成三角形对象
a1.output();
Jux a2=new Jux(7.6,9); //生成矩形对象
a2.output();
Yuanx a3=new Yuanx(9.3); //生成圆形对象
a3.output();
}
public static void main(String args[]){
Area a=new Area();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -