01: import java.awt.*; 02: import java.awt.geom.*; 03: 04: /** 05: A car shape. 06: */ 07: public class CarShape extends CompoundShape 08: { 09: /** 10: Constructs a car shape. 11: @param x the left of the bounding rectangle 12: @param y the top of the bounding rectangle 13: @param width the width of the bounding rectangle 14: */ 15: public CarShape(int x, int y, int width) 16: { 17: Rectangle2D.Double body 18: = new Rectangle2D.Double(x, y + width / 6, 19: width - 1, width / 6); 20: Ellipse2D.Double frontTire 21: = new Ellipse2D.Double(x + width / 6, y + width / 3, 22: width / 6, width / 6); 23: Ellipse2D.Double rearTire 24: = new Ellipse2D.Double(x + width * 2 / 3, 25: y + width / 3, 26: width / 6, width / 6); 27: 28: // the bottom of the front windshield 29: Point2D.Double r1 30: = new Point2D.Double(x + width / 6, y + width / 6); 31: // the front of the roof 32: Point2D.Double r2 33: = new Point2D.Double(x + width / 3, y); 34: // the rear of the roof 35: Point2D.Double r3 36: = new Point2D.Double(x + width * 2 / 3, y); 37: // the bottom of the rear windshield 38: Point2D.Double r4 39: = new Point2D.Double(x + width * 5 / 6, y + width / 6); 40: Line2D.Double frontWindshield 41: = new Line2D.Double(r1, r2); 42: Line2D.Double roofTop 43: = new Line2D.Double(r2, r3); 44: Line2D.Double rearWindshield 45: = new Line2D.Double(r3, r4); 46: 47: add(body); 48: add(frontTire); 49: add(rearTire); 50: add(frontWindshield); 51: add(roofTop); 52: add(rearWindshield); 53: } 54: }