-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathLadder.java
More file actions
68 lines (53 loc) · 1.36 KB
/
Ladder.java
File metadata and controls
68 lines (53 loc) · 1.36 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
package ladder1;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Ladder {
private int width;
private int height;
private List<String> ladder;
private int[] randomArray;
public Ladder(int width, int height) {
this.width = width;
this.height = height;
this.ladder = new ArrayList<>();
this.randomArray = new int[width - 1];
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public List<String> getLadder() {
return ladder;
}
public void setWidth(int w) {
this.width = w;
}
public void setHeight(int h) {
this.height = h;
}
private void makeRandom(int i) {
Random random = new Random();
if (i == 0) {
randomArray[i] = random.nextInt(2);
return;
}
if (randomArray[i - 1] == 0) {
randomArray[i] = random.nextInt(2);
}
if (randomArray[i - 1] == 1) {
randomArray[i] = 0;
}
}
private String change(int i) {
return randomArray[i] == 0 ? " " : "-----";
}
public void makeLadder() {
for (int i = 0; i < width - 1; i++) { // width - 1까지 반복
makeRandom(i);
ladder.add(change(i));
}
}
}