Question: // I don't get right result in getting polygon area. class RegularPolygon { private int n; private double side; private double x; private double y;

// I don't get right result in getting polygon area.

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.n = n;

this.side = side;

}

public RegularPolygon(int n, double side, double x, double y) {

this.n = n;

this.side = side;

this.x = x;

this.y = y;

}

public int getNumberOfSides() {

return this.n;

}

public void setNumberOfSides(int n) {

this.n = n;

}

public double getSide() {

return this.side;

}

public void setSide(double side) {

this.side = side;

}

public double getX() {

return this.x;

}

public void setX(double x) {

this.x = x;

}

public double getY() {

return this.y;

}

public void setY(double y) {

this.y = y;

}

public double getPerimeter() {

return this.n * this.side;

}

public double getArea() {

return ((this.n * Math.pow(this.side,2)) / (4 * Math.tan(Math.PI) / this.n));

}

}

public class ss {

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());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!