Question: using Java Problem 2: n-sided regular polygon In n-sided regular polygon, all sides have the same length and all angles have the same degree Design
Problem 2: n-sided regular polygon In n-sided regular polygon, all sides have the same length and all angles have the same degree Design and write a Java class named RegularPolygon.java that contains: A data field named n that defines the number of sides in the polygon, with default value 3. A data field named side that stores the length of the side, with default value 1.0. A data field named x that defines the x-coordinate of the polygon's center with default value O. A data field named y that defines the y-coordinate of the polygon's center with default value 0. A datafield named nbOfPolygons that stores the number of created polygon objects. A no-arg constructor that creates a regular polygon with default values. A constructor that creates a regular polygon with the specified number of sides and length of side, centered at (0,0). A constructor that creates a regular polygon with the specified number of sides, length of side, and x-and y-coordinates The get and set methods for all private data fields. . The method getPerimeter() that returns the perimeter of the polygon. The method getArea) that returns the area of the polygon. The formula for computing the area of a regular polygon is: Area 4 x tan The method toString() that returns the polygon number, its perimeter and area similarly to the sample output below. Write a test program, TestRegularPolygon.java that creates three RegularPolygon objects using appropriate constructors as follows: The first regular polygon will have default values for all members. - The second regular polygon will have number of sides = 6 and side length - 4. -The third regular polygon will have number of sides = 10, side length = 4, and (x,y) = (5.6, 7-8). For each polygon object, display its number, perimeter and area, as shown in the sample below. Sample output Polygon 1: Perimeter - 3.0, Area - 0.43 Polygon 2: Perimeter - 24.0, Area - 41.57 Polygon 3: Perimeter 40.00, Area - 123.11
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
