Question: I should be getting this result above. Help me point out the error in this code because it gives different result. class RegularPolygon { private

I should be getting this result above.
Help me point out the error in this code because it gives different result.
class RegularPolygon {
private int n;
private double side;
private double x;
private double y;
public RegularPolygon(){
n = 3;
side = 1;
x = 0;
y = 0;
}
public RegularPolygon(int n, double side) {
this();
this.n = n;
this.side = side;
}
public RegularPolygon(int n, double side, double x, double y) {
this();
this.n = n;
this.side = side;
this.x = x;
this.y = y;
}
public int getNumberOfSides() {
return n;
}
public void setNumberOfSides(int newN) {
n = newN;
}
public double getSide() {
return side;
}
public void setSide(double newSide) {
side = newSide;
}
public double getX() {
return x;
}
public void setX(double newX) {
x = newX;
}
public double getY() {
return y;
}
public void setY(double newY) {
y = newY;
}
public double getPerimeter() {
return n * side;
}
public double getArea() {
return (n * side * side) / (4 * Math.tan(Math.PI) / n);
}
}
public class Exercise9_9 {
public static void main(String[] args) {
RegularPolygon regularPolygon1 = new RegularPolygon();
RegularPolygon regularPolygon2 = new RegularPolygon(6, 4);
RegularPolygon regularPolygon3 = new RegularPolygon(10, 3, 5.6, 7.8);
System.out.println("\t|Perimeter " + "\t" + "| Area ");
System.out.println(" Object1| " + regularPolygon1.getPerimeter() + "\t\t| " + regularPolygon1.getArea());
System.out.println(" Object2| " + regularPolygon2.getPerimeter() + "\t\t| " + regularPolygon2.getArea());
System.out.println(" Object3| " + regularPolygon3.getPerimeter() + "\t\t| " + regularPolygon3.getArea());
}
}
Sample Output: RegularPolygon using no-arg constructor Perimeter: 3 Area: 0.433013 RegularPolygon (6, 4) Perimeter: 24 Area: 41.5692 RegularPolygon (10, 4,5.6,7.8 Perimeter: 40 Area: 123.107
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
