Question: Python Design a class named RegularPolygon containing the following: 1 . An int data field named n defines the number of sides in the polygon.

Python
Design a class named RegularPolygon containing the following:
1. An int data field named n defines the number of sides in the polygon.
2. A float data field named side stores the length of the side.
3. A float data field named x defines the x-coordinate of the center of the polygon with a default value of 0.
4. A float data field named y defines the y-coordinate of the center of the polygon with a default value of 0.
5. A constructor that creates a regular polygon with the specified n (default 3), side (default 1), x (default 0), and y (default 0).
6. The accessor and mutator methods for all data fields.
7. The method getPerimeter() returns the perimeter of the polygon.
8. The method getArea() returns the area of the polygon.
Create three RegularPolygon objects
A. using RegularPolygon()
B. using RegularPolygon(6,4)
C. using RegularPolygon(10,4,5.6,7.8)

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!