-
Notifications
You must be signed in to change notification settings - Fork 748
/
Copy pathPrintView.java
49 lines (42 loc) · 1.23 KB
/
PrintView.java
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
package ladder.ui;
import ladder.Ladder;
import ladder.Line;
import java.util.List;
public class PrintView {
public static void printResult(List<String> names, Ladder ladder) {
System.out.println("실행결과");
printName(names);
printLadder(ladder);
}
private static void printName(List<String> names) {
names.stream()
.map(name -> {
int padding = 5 - name.length();
String paddedName = name + " ".repeat(padding);
return paddedName;
})
.forEach(System.out::print);
System.out.println();
}
private static void printLadder(Ladder ladder) {
List<Line> lines = ladder.getLines();
lines.forEach(line -> {
printColumn();
line.getPoints().forEach(point -> {
printRow(point);
printColumn();
});
System.out.println();
});
}
private static void printColumn(){
System.out.print("|");
}
private static void printRow(boolean point){
if(point){
System.out.print("-----");
} else{
System.out.print(" ");
}
}
}