-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathRaceController.java
More file actions
42 lines (35 loc) · 1.35 KB
/
RaceController.java
File metadata and controls
42 lines (35 loc) · 1.35 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
import domain.Attempts;
import domain.RacingGame;
import dto.ResultDto;
import view.InputView;
import view.OutputView;
import java.io.IOException;
import java.util.List;
public class RaceController {
private static final InputView inputView = new InputView(System.in);
public static void main(String[] args) {
final RacingGame racingGame = repeatUntilGetValidCarNames();
final Attempts attempts = repeatUntilGetValidAttempts();
List<ResultDto> raceProcess = racingGame.race(attempts);
OutputView.printRaceProcess(raceProcess);
OutputView.printResult(racingGame.getWinners());
}
private static RacingGame repeatUntilGetValidCarNames() {
try {
final String[] carNames = inputView.readCarNames();
return new RacingGame(carNames);
} catch (IOException | IllegalArgumentException e) {
OutputView.printExceptionMessage(e);
return repeatUntilGetValidCarNames();
}
}
private static Attempts repeatUntilGetValidAttempts() {
try {
final Integer numberOfAttempts = inputView.readNumberOfAttempts();
return new Attempts(numberOfAttempts);
} catch (IOException | IllegalArgumentException e) {
OutputView.printExceptionMessage(e);
return repeatUntilGetValidAttempts();
}
}
}