Java Reference
In-Depth Information
30 public static void drawBox() {
31 System.out.println("+------+");
32 System.out.println("| |");
33 System.out.println("| |");
34 System.out.println("+------+");
35 }
36
37 public static void drawCone() {
38 System.out.println(" /\\");
39 System.out.println(" / \\");
40 System.out.println(" / \\");
41 }
42
43 public static void drawV() {
44 System.out.println(" \\ /");
45 System.out.println(" \\ /");
46 System.out.println(" \\/");
47 }
48 }
This program, now called DrawFigures3 , has seven static methods defined within
it. The first static method is the usual main method, which calls three methods. These
three methods in turn call three other methods, which appear next.
Analysis of Flow of Execution
The structure diagram in Figure 1.4 shows which static methods main calls and
which static methods each of them calls. As you can see, this program has three levels
of structure and two levels of decomposition. The overall task is split into three
subtasks, each of which has two subtasks.
A program with methods has a more complex flow of control than one without
them, but the rules are still fairly simple. Remember that when a method is called, the
computer executes the statements in the body of that method. Then the computer pro-
ceeds to the next statement after the method call. Also remember that the computer
always starts with the main method, executing its statements from first to last.
main
drawDiamond
drawX
drawRocket
drawCone
drawV
drawV
drawCone
drawCone
drawBox
Figure 1.4
Decomposition of DrawFigures3
 
Search WWH ::




Custom Search