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