Java Reference
In-Depth Information
The output we want to produce is the following:
+------+
|\..../|
| \../ |
| \/ |
| /\ |
| /..\ |
|/....\|
+------+
Problem Decomposition and Pseudocode
To generate this figure, you have to first break it down into subfigures. In doing so,
you should look for lines that are similar in one way or another. The first and last
lines are exactly the same. The three lines after the first line all fit one pattern, and
the three lines after that fit another:
line
+------+
|\..../|
| \../ |
top half
| \/ |
| /\ |
| /..\ |
bottom half
|/....\|
line
+------+
Thus, you can break down the overall problem as follows:
draw a solid line.
draw the top half of the hourglass.
draw the bottom half of the hourglass.
draw a solid line.
You should solve each subproblem independently. Eventually you'll want to incor-
porate a class constant to make the program more flexible, but let's first solve the
problem without worrying about the use of a constant.
The solid line task can be further specified as
write a plus on the output line.
write 6 dashes on the output line.
write a plus on the output line.
go to a new output line.
This set of instructions translates easily into a static method:
 
Search WWH ::




Custom Search