-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathRacingController.java
More file actions
51 lines (41 loc) · 1.5 KB
/
RacingController.java
File metadata and controls
51 lines (41 loc) · 1.5 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
package controller;
import java.util.List;
import model.dto.RaceResultDto;
import model.entity.Car;
import service.RacingService;
import validation.Validation;
import view.InputView;
import view.OutputView;
public class RacingController {
public final RacingService racingService;
public RacingController(RacingService racingService) {
this.racingService = racingService;
}
public void runRacingSystem() {
// 사용자 입력 처리
String[] carNames = getCarNames();
int attemptCount = getAttemptCount();
// 경주 진행 및 각 시도 결과 출력
OutputView.printCarRacingResultHeader();
List<List<Car>> eachRaceResults = racingService.startRace(carNames, attemptCount);
eachRaceResults.forEach(OutputView::printRaceResult);
// 최종 우승자 계산 및 출력
printWinners(eachRaceResults.get(eachRaceResults.size() - 1));
}
private String[] getCarNames() {
OutputView.printEnterCarNamesOutputMessage();
String[] carNames = InputView.getCarNamesInput();
Validation.validCarNames(carNames);
return carNames;
}
private int getAttemptCount() {
OutputView.printEnterAttemptCountMessage();
String attemptCountInput = InputView.getAttemptCountInput();
Validation.validAttemptCountInput(attemptCountInput);
return Integer.parseInt(attemptCountInput);
}
private void printWinners(List<Car> finalCars) {
RaceResultDto raceResultDto = new RaceResultDto(finalCars);
OutputView.printWinners(raceResultDto.getWinnerNames());
}
}