-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathOutput.java
More file actions
39 lines (32 loc) · 1.45 KB
/
Output.java
File metadata and controls
39 lines (32 loc) · 1.45 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
package view;
import model.RacingCar;
import java.util.List;
import java.util.stream.Collectors;
public class Output {
private static final String LINE_SEPARATOR = System.lineSeparator();
private static final String RESULT_MESSAGE = "실행 결과";
private static final String STATUS_PRINT_FORMAT = "%s : %s" + LINE_SEPARATOR;
private static final String WINNER_PRINT_FORMAT = "%s가 최종 우승했습니다." + LINE_SEPARATOR;
private static final String WORD_DELIMITER = ", ";
private static final String POSITION_SYMBOL = "-";
public static void printResult() {
System.out.println(RESULT_MESSAGE);
}
public static void printStatus(final List<RacingCar> racingCars) {
for (RacingCar car : racingCars) {
String currentPosition = getCurrentPosition(car.getPosition());
System.out.printf(STATUS_PRINT_FORMAT, car.getName(), currentPosition);
}
System.out.println();
}
private static String getCurrentPosition(final int position) {
return POSITION_SYMBOL.repeat(Math.max(0, position));
}
public static void printWinners(final List<RacingCar> racingCars) {
List<String> carNames = racingCars.stream() //리스트를 스트림하는 부분
.map(RacingCar::getName)
.collect(Collectors.toList());
String winners = String.join(WORD_DELIMITER, carNames);
System.out.printf(WINNER_PRINT_FORMAT, winners);
}
}