Homework 2
Before attempting this project, be sure you have completed all of the reading assignments, hands-on
labs, discussions, and assignments to date.
(25 points) Design a Java class named Polygon that contains:
Be sure your code compiles.
Next, write a Java test program, named TestPolygon, to create five different polygons. When
creating the five polygons, create one using the no argument constructor. For the remaining four,
feel free to use any number of sides, side length and x-, and y-coordinates and apothem that are not
equal to the default values and not equal to each other. For each of the five polygons, call all of the
methods and display the results. For example for a Polygon with 3 sides, side length of 2.0 and x-
coordinate and y-coordinates of 1.0, and apothem of 1.0 the following output may result:
toString() results: (numsides=3, sideLength=2.0,
xcoord=1.0,ycoord=1.0, apothem=1.0)
getNumSides() results: 3
getSideLength() results: 2.0
getXCoord() results: 1.0
getYCoord() results: 1.0
getApothem() results:1.0
getPerimeter() results: 6.0
getArea() results: 3.0
setNumSides(4) results: 4
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 1 | 2 | 3 | 4 | 5 |