9.9
其他题目在上一节
class RegularPolygon{
private int n=3;
private double side=1;
private double x=0.0;
private double y=0.0;
public RegularPolygon(int n,double size){
this.n=n;
this.side=side;
}
public RegularPolygon(){}
public RegularPolygon(int n,double side,double x,double y){
this.n=n;
this.side=side;
this.x=x;
this.y=y;
}
public int getN(){
return n;
}
public double getSide(){
return side;
}
public double getX(){
return x;
}
public double getY(){
return y;
}
public double getPerimeter(){
return n*side;
}
public double getArea(){
return (n*side*side)/4*(Math.atan(Math.PI/n));
}
public static void main(String[] args){
RegularPolygon r1 = new RegularPolygon(6,4,0,0);
RegularPolygon r2 = new RegularPolygon(10,4,5.6,7.8);
RegularPolygon r3 = new RegularPolygon();
System.out.println("[Perimeter:"+String.format("%.2f",r1.getPerimeter())+" Area:"+String.format("%.2f",r1.getArea())+"]");
System.out.println("[Perimeter:"+String.format("%.2f",r2.getPerimeter())+" Area:"+String.format("%.2f",r2.getArea())+"]");
System.out.println("[Perimeter:"+String.format("%.2f",r3.getPerimeter())+" Area:"+String.format("%.2f",r3.getArea())+"]");
}
}