    01: import java.awt.*;
    02: import java.awt.geom.*;
    03:
    04: /**
    05:    A house shape.
    06: */
    07: public class HouseShape extends CompoundShape
    08: {
    09:    /**
    10:       Constructs a house 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 HouseShape(int x, int y, int width)
    16:    {
    17:       Rectangle2D.Double base
    18:          = new Rectangle2D.Double(x, y + width, width, width);
    19:
    20:       // the left bottom of the roof
    21:       Point2D.Double r1
    22:          = new Point2D.Double(x, y + width);
    23:       // the top of the roof
    24:       Point2D.Double r2
    25:          = new Point2D.Double(x + width / 2, y);
    26:       // the right bottom of the roof
    27:       Point2D.Double r3
    28:          = new Point2D.Double(x + width, y + width);
    29:
    30:       Line2D.Double roofLeft
    31:          = new Line2D.Double(r1, r2);
    32:       Line2D.Double roofRight
    33:          = new Line2D.Double(r2, r3);
    34:
    35:       add(base);
    36:       add(roofLeft);
    37:       add(roofRight);
    38:    }
    39: }