-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathView.java
More file actions
55 lines (48 loc) · 1.74 KB
/
View.java
File metadata and controls
55 lines (48 loc) · 1.74 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
package view;
import model.Car;
import java.util.List;
import java.util.Scanner;
public class View {
private final Scanner scanner = new Scanner(System.in);
/**
* 사용자로부터 자동차 이름을 입력받는 메서드
* @return 입력받은 자동차 이름 리스트
*/
public List<String> getCarNames() {
while (true) {
try {
System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)");
String input = scanner.nextLine();
String[] names = input.split(",");
for (String name : names) {
new Car(name); // 이 과정에서 예외가 발생할 수 있음
}
return List.of(names);
} catch (IllegalArgumentException e) {
System.out.println("[ERROR] " + e.getMessage());
}
}
}
/**
* 사용자로부터 시도할 회수를 입력받는 메서드
* @return 입력받은 시도할 회수
*/
public int getTrialCount() {
while (true) {
try {
System.out.println("시도할 회수는 몇회인가요?");
return Integer.parseInt(scanner.nextLine());
} catch (NumberFormatException e) {
System.out.println("[ERROR] 유효한 숫자를 입력하세요.");
}
}
}
public void displayRaceResult(List<Car> cars) {
for (Car car : cars) {
System.out.println(car.getName() + " : " + "-".repeat(car.getPosition()));
}
}
public void displayWinners(List<String> winners) {
System.out.println("최종 우승자 : " + String.join(", ", winners));
}
}