-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirecracker.java
More file actions
131 lines (101 loc) · 3.58 KB
/
Firecracker.java
File metadata and controls
131 lines (101 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Derrick Cheah
// CS 210
// HW Core Topics: For Loops, Static Methods, Print/Println Statements, Class Constant
//
// This program will produce an ASCII Art Firecracker with a size specified by a class constant.
public class Firecracker {
public static final int SIZE = 4;
public static void main(String[] args) {
cone(SIZE);
i_equals(SIZE);
equals(SIZE);
upper_body(SIZE);
i_equals(SIZE);
equals(SIZE);
lower_body(SIZE);
i_equals(SIZE);
equals(SIZE);
tail(SIZE);
}
//This method prints the cone portion of the firecracker
public static void cone(int size) {
for (int line = 1; line <= (size + 1); line++) {
space(-line + (size + 1));
System.out.print("/");
for (int x = 1; x <= ((2 * line) - 1); x++) {
System.out.print("x");
}
System.out.print("\\");
space(-line + (size + 1));
System.out.println();
}
}
//This method prints out multiple spaces within the firecracker.
//This method was written to save some lines of repetitive code.
public static void space(int size) {
for (int space = size; space >= 1; space--) {
System.out.print(" ");
}
}
//This method prints out the first connection portion of the firecracker denoted by various "I=" statements.
public static void i_equals(int size) {
System.out.print("[=");
for (int i = 1; i <= size; i++) {
System.out.print("I=");
}
System.out.print("]");
System.out.println();
}
//This method prints out the second connection portion of the firecracker denoted by "=" signs.
public static void equals(int size) {
for (int equals = 1; equals <= (2*size + 3); equals++) {
System.out.print("=");
}
System.out.println();
}
//This method prints out the upper portion of the body of the firecracker.
public static void upper_body(int size) {
for (int line = 1; line <= (size - 2); line++) {
System.out.print(" |");
for (int l = 1; l <= (size - 1); l++) {
System.out.print("-|");
}
System.out.print(" ");
System.out.println();
}
}
//This method prints out the lower portion of the body of the firecracker.
public static void lower_body(int size) {
for (int line = 1; line <= size; line++) {
System.out.print(" |");
dots(line - 1);
for (int tilde = 1; tilde <= (-2 * line + (2 * size + 1)); tilde++) {
System.out.print("~");
}
dots(line - 1);
System.out.print("| ");
System.out.println();
}
}
//This method prints out the dots used in the lower portion of the firecracker body.
//This method was written to save some lines of repetitive code.
public static void dots(int n) {
for (int dots = 1; dots <= n; dots++) {
System.out.print(".");
}
}
//This method prints out the tail of the firecracker.
public static void tail(int size) {
for (int line = 1; line <= (size - 1); line++) {
space(-line + (size+2));
for (int forward = 1; forward <= (line - 1); forward++) {
System.out.print("/");
}
System.out.print("|");
for (int back = 1; back <= (line - 1); back++) {
System.out.print("\\");
}
System.out.println();
}
}
}