Java Genesis

Hints for Chapter 7: Objects and Classes

Problem 5: drawing regular polygons

To draw a regular pentagon, all we need to do is take the code for the regular hexagon, set the array vertices to be of length 5 rather than 6, and observe that the angle from the centre between successive vertices is now 2*pi/5. Only the main method will need to be modified; the method getVertex will be unchanged.

Try this before looking at the next hint.


Next Hint