Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Questlon i Geometry: n-sided regular polygon) An n-sided regular polygon has n p

ID: 3911129 • Letter: Q

Question

Questlon i Geometry: n-sided regular polygon) An n-sided regular polygon has n pides of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon that contains: A private int data tield named n that definea the number of sides in the polygon with default value 3 A private double data tield named side that stores the length of the aide with default value i . A private double data field named x that defines the x-coordinate of the center of the polygon with default value . A private double data tield named y that defines the y-coordinate of the center of the polygon with default value g A no-arg conatructor that creates a regular polygon with default values. A constructor that creates a regular polygon with the specified number of sides and the length of side, and centered at (. ) .A constructor that creates a regular polygon with the specified number of sides, the length ot side, and x-and y-coordinates The accessor and mutator methods for al1 data tields. · The method getPerinter() that returns the perimeter of the polygon. The perimeter is the addition of the length of all the side? of the polygon. . The method getAreal) that returns the area of the polygon. The formula for computing the area of a regular polygon is Area= . Use the Hath . tan (double) method which also returns a 4 x tan(*) double 25 points Question #2 Create a testing class which will create tvo RegularPolygon objects and if the two objects are the same display then display a message stating both objects contain the same information. If the two objects are not the same then copy all the information from the second object into the first one. Do not assign the objects. You need to copy all the information from second object into the first one. You will need to create two more methods in the RegularPolygon class: equals checks if the information of two objects are the same copy copies the information of one object into another 25 points Question #3 Create a testing class which wil1 create 5 RegularPolygon objects. Set the side with a random number from 2 to 10 and set n with a random number from 3 to 8. Display the following for each po1ygon: . Perimeter .Area .Type of Polygon Type Polygon is based on the number of sides Sides Type Triangle Quadrilateral Pentagon Hexagon Heptagon Octagon

Explanation / Answer

import java.lang.*;

public class RegularPolygon{

private int n;

private double side;

private double x;

private double y;

RegularPolygon(int n, double side){

this.setn(n);

this.setside(side);

this.setx(0);

this.sety(0);

}

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

this.setn(n);

this.setside(side);

this.setx(x);

this.sety(y);

}

public double getPerimeter(){

return (this.getn()*this.getside());

}

public double getArea(){

// System.out.println(((this.getn()*(this.getside()*this.getside()))/(4*Math.tan(Math.PI/this.getn()))));

return ((this.getn()*(this.getside()*this.getside()))/(4*Math.tan(Math.PI/this.getn())));

}

public int getn(){

return this.n;

}

public void setn(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 static void main(String[] args) {

RegularPolygon p1=new RegularPolygon(3,4.0);

System.out.println(p1.getArea());

System.out.println(p1.getPerimeter());

RegularPolygon p2=new RegularPolygon(4,5.0,1,2);

System.out.println(p2.getArea());

System.out.println(p2.getPerimeter());

}

}