public interface J_Shape
{
public abstract double Area();不满抱怨的话叫//计算并返回N边形的面积
public 几何画板官网abstract double Perimeter();//计算并返回N边形的面积
}
public class J_Point
{
public double x,y;
J_Point(double _x,double _y)
{
x=_x;
y=_y;
}
public double distance(J_Point _P)//求两点之间的距离
{
double s;
s=Math.sqrt(Math.pow(x-_P.x,2)+Math.pow(y-_P.y,2));
return s;
}
}
public心脉通 class J_Triangle implements J_Shape
{
public J_Point PA,PB,PC;
public J_Triangle(J_Point _PA,J_Point _PB,J_Point _PC)
{
if((_PA.x==_PB.x&_PA.x==_PC.x)||(_PA.y==_PB.y&_PA.y==_PC.y))//判断三角形的三个点不在一条直线上
System.out.println("该三个点不能组成三角形");
el
{
PA=_PA;
PB=_PB;
PC=_PC;
}
}
public double Sin(J_Point PA,J_Point PB,J_Point PC)
{
double sin,cos;
double a,b,c;
武汉大学校门 a=Math.sqrt((PA.x-PC.x)*(PB.x-PC.x)+(PB.y-PC.y)*(PB.y-PC.y));
b=Math.sqrt((PA.x-PC.x)*(PA.x-PC.x)+(PA.y-PC.y)*(PA.y-PC.y));
c=Math.sqrt((PA.x-PB.x)*(PA.x-PB.x)+(PA.y-PB.y)*(PA.y-PB.y));
cos=(a*a+b*b-c*c)/(2*a*b);
sin=Math.sqrt(1-cos*cos);
return sin;
}
public double Perimeter()//求三角形周长
{
return PA.distance(PB)+PB.distance(PC)+PA.distance(PC);
}
public double Area()//求三角形面积
剑兰的花语 {
return (0.5*PB.distance(PC)*PA.distance(PC)*Sin(PA,PB,PC));
}
}
public class J_Square implements J_Shape
{
public J_Point P1,P2;//P1,P2分别为正方形的两个对角点
public J_Square(J_Point _P1,J_Point _P2)
{
P1=_P1;
七夕情 P2=_P2;
}
public double Perimeter()//求正方形周长
{
return 4*P1.distance(P2)/Math.sqrt(2);
}
public什么是ted演讲 double Area()//求正方形面积
{
return P1.distance(P2)*P1.distance(P2)/2;
}
}
public class J_Circle implements J_Shape
{
public double x,y;//圆心坐标
无伤大雅什么意思 public double R;
public J_Circle(double r)
{
x=0;
y=0;//圆心位于原点
R=r;
}
public double Area()
{
return (Math.PI*R*R);
}
public double Perimeter()
{
return(Math.PI*R*2);
}
}
public class J_Pentagon implements J_Shape
{
public J_Point Pa,Pb;
public double r;
public J_Pentagon(J_Point _Pa,J_Point _Pb)
{
Pa=_Pa;
Pb=_Pb;
}
public double J_Lenth()//正五边形的边长公式
{
double L;
double cos;
cos=Math.cos(Math.PI*54/180);
r=Pa.distance(Pb);
L=2*r*cos;
return L;
}
public double J_Area()//正五边形中一个三角形的面积公式
{
double S;
double sin;
sin=Math.sin(Math.PI*72/180);
r=Pa.distance(Pb);
S=0.5*r*r*sin;
return S;
}
public double Perimeter()//求正五边形的周长
{
return 5*J_Lenth();
}
public double Area()//求正五边形的面积
{
return J_Area()*5;
}
}
public class J_Answer
{
public static void main(String args[])
{
J_Point PA = new J_Point(5, 6);
J_Point PB = new J_Point(3, 1);
J_Point PC = new J_Point(9, 5);
J_Triangle T = new J_Triangle(PA, PB, PC);
System.out.println("三角形周长是:"+ T.Perimeter());
System.out.println("三角形面积是:"+ T.Area());
J_Point P1 = new J_Point(0, 0);
J_Point P2 = new J_Point(4, 4);
J_Square S = new J_Square(P1, P2);
System.out.println("正方形周长是:" + S.Perimeter());
System.out.println("正方形面积是:" + S.Area());
J_Shape a=new J_Circle(5);
System.out.println("半径为5的圆的面积是"+a.Area());
System.out.println("半径为5的圆的周长是"+a.Perimeter());
J_Point Pa = new J_Point(0, 0);//中心点
J_Point Pb = new J_Point(5, 5);//其中一个点
J_Pentagon F = new J_Pentagon(Pa,Pb);
System.out.println("正五边形周长是" + F.Perimeter());
System.out.println("正五边形面积是" + F.Area());
}
}
运行结果:
三角形周长是:16.71937298368014
三角形面积是:12.541929676090517
正方形周长是:16.0
正方形面积是:16.000000000000004
半径为5的圆的面积是78.53981633974483
半径为5的圆的周长是31.41592653589793
正五边形周长是41.562693777745345
正五边形面积是118.8820645368942