01: /**
02:    A triangular shape composed of stacked unit squares like this:
03:    []
04:    [][]
05:    [][][]
06:    . . .
07: */
08: public class Triangle
09: {
10:    /**
11:       Constructs a triangular shape.
12:       @param aWidth the width (and height) of the triangle
13:    */
14:    public Triangle(int aWidth)
15:    {
16:       width = aWidth;
17:    }
18: 
19:    /**
20:       Computes the area of the triangle.
21:       @return the area
22:    */
23:    public int getArea()
24:    {
25:       if (width <= 0) return 0;
26:       if (width == 1) return 1;
27:       Triangle smallerTriangle = new Triangle(width - 1);
28:       int smallerArea = smallerTriangle.getArea();
29:       return smallerArea + width;
30:    }
31: 
32:    private int width;
33: }