public class TreeDemo
1:
2: /**
3: A program that draws a fir tree composed of a triangle and
4: a rectangle, both drawn using keyboard characters.
5: */
6: public class TreeDemo
7: {
8: public static final int INDENT = 5;
9: public static final int TREE_TOP_WIDTH = 21;// must be odd
10: public static final int TREE_BOTTOM_WIDTH = 4;
11: public static final int TREE_BOTTOM_HEIGHT = 4;
12:
13: public static void main(String[] args)
14: {
15: drawTree(TREE_TOP_WIDTH, TREE_BOTTOM_WIDTH, TREE_BOTTOM_HEIGHT);
16: }
17:
18: public static void drawTree(int topWidth, int bottomWidth, int bottomHeight)
19: {
20: System.out.println(" Save the Redwoods!");
21: TriangleInterface treeTop = new Triangle(INDENT, topWidth);
22: drawTop(treeTop);
23:
24: RectangleInterface treeTrunk = new Rectangle(INDENT + (topWidth / 2) - (bottomWidth / 2),
25: bottomHeight, bottomWidth);
26: drawTrunk(treeTrunk);
27: }
28:
29: private static void drawTop(TriangleInterface treeTop)
30: {
31: treeTop.drawAt(1);
32: }
33:
34: private static void drawTrunk(RectangleInterface treeTrunk)
35: {
36: treeTrunk.drawHere(); // or treeTrunk.drawAt(0);
37: }
38: }