1 /* 2 * File: Octagon.java 3 * 4 * Octagon class 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.awt.Point; 11 12 // An octagon is a polygon with eight sides: 13 public class Octagon extends MovablePolygon { 14 15 // Octagon constructor #1: 16 public Octagon() { 17 // invoke the no-argument constructor of the superclass: 18 super(); 19 } 20 21 // Octagon constructor #2: 22 public Octagon( int x1, int y1, 23 int x2, int y2, 24 int x3, int y3, 25 int x4, int y4, 26 int x5, int y5, 27 int x6, int y6, 28 int x7, int y7, 29 int x8, int y8 ) { 30 31 // invoke the no-argument constructor of the superclass: 32 super(); 33 34 // the 'this' reference is optional: 35 this.addPoint( x1, y1 ); this.addPoint( x2, y2 ); 36 this.addPoint( x3, y3 ); this.addPoint( x4, y4 ); 37 this.addPoint( x5, y5 ); this.addPoint( x6, y6 ); 38 this.addPoint( x7, y7 ); this.addPoint( x8, y8 ); 39 40 } 41 42 // Octagon constructor #3: 43 public Octagon( Point p1, Point p2, 44 Point p3, Point p4, 45 Point p5, Point p6, 46 Point p7, Point p8 ) { 47 48 // invoke Octagon constructor #2: 49 this( p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, 50 p5.x, p5.y, p6.x, p6.y, p7.x, p7.y, p8.x, p8.y ); 51 52 } 53 54 // Octagon constructor #4 (a regular octagon centered 55 // at point (x,y) of radius r ): 56 public Octagon( int x, int y, int r ) { 57 // invoke the corresponding constructor of the superclass: 58 super( x, y, r, 8 ); 59 } 60 61 }