@@ -24,32 +24,31 @@ public RegularPolygon(int nsides) {
2424 }
2525
2626 /**
27- * Constructs a regular polygon, given the number of sides and length of
28- * each side.
27+ * Constructs a regular polygon, given the number of sides and the radius.
2928 *
3029 * @param nsides the number of sides
31- * @param length length of each side
30+ * @param radius from center to vertex
3231 */
33- public RegularPolygon (int nsides , int length ) {
34- this (nsides , length , Color .BLACK );
32+ public RegularPolygon (int nsides , int radius ) {
33+ this (nsides , radius , Color .BLACK );
3534 }
3635
3736 /**
38- * Constructs a regular polygon, given the number of sides, the length of
39- * each side, and fill color.
37+ * Constructs a regular polygon, given the number of sides, the radius, and
38+ * fill color.
4039 *
4140 * @param nsides the number of sides
42- * @param length length of each side
41+ * @param radius from center to vertex
4342 * @param color initial fill color
4443 */
45- public RegularPolygon (int nsides , int length , Color color ) {
44+ public RegularPolygon (int nsides , int radius , Color color ) {
4645
4746 // validate and store arguments
4847 if (nsides < 3 ) {
4948 throw new IllegalArgumentException ("invalid nsides" );
5049 }
51- if (length < 1 ) {
52- throw new IllegalArgumentException ("invalid length " );
50+ if (radius < 1 ) {
51+ throw new IllegalArgumentException ("invalid radius " );
5352 }
5453 if (color == null ) {
5554 throw new NullPointerException ("invalid color" );
@@ -61,9 +60,6 @@ public RegularPolygon(int nsides, int length, Color color) {
6160 this .ypoints = new int [nsides ];
6261 this .color = color ;
6362
64- // radius of the polygon (distance from center to vertex)
65- double radius = 0.5 * length / Math .sin (Math .PI / nsides );
66-
6763 // the angle (in radians) at each vertex
6864 double angle = 2.0 * Math .PI / nsides ;
6965
@@ -81,12 +77,11 @@ public RegularPolygon(int nsides, int length, Color color) {
8177
8278 @ Override
8379 public void step () {
84- // nothing to do
80+ // do nothing
8581 }
8682
8783 @ Override
8884 public void draw (Graphics g ) {
89- // System.out.println(this);
9085 g .setColor (color );
9186 g .fillPolygon (this );
9287 }
0 commit comments