Java Reference
In-Depth Information
The program can still be improved. Each of the three subfigures has individual ele-
ments, and some of those elements appear in more than one of the three subfigures.
The program prints the following redundant group of lines several times:
/\
/ \
/ \
A better version of the preceding program adds an additional method for each
redundant section of output. The redundant sections are the top and bottom halves of
the diamond shape and the box used in the rocket. Here is the improved program:
1
public class
DrawFigures3 {
2
public static void
main(String[] args) {
3 drawDiamond();
4 drawX();
5 drawRocket();
6 }
7
8
public static void
drawDiamond() {
9 drawCone();
10 drawV();
11 System.out.println();
12 }
13
14
public static void
drawX() {
15 drawV();
16 drawCone();
17 System.out.println();
18 }
19
20
public static void
drawRocket() {
21 drawCone();
22 drawBox();
23 System.out.println("|United|");
24 System.out.println("|States|");
25 drawBox();
26 drawCone();
27 System.out.println();
28 }
29
Search WWH ::
Custom Search