forked from woowacourse/java-blackjack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputController.java
More file actions
55 lines (47 loc) · 1.4 KB
/
InputController.java
File metadata and controls
55 lines (47 loc) · 1.4 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 controller;
import domain.Answer;
import domain.participant.Players;
import exception.CustomException;
import java.util.List;
import view.InputView;
import view.OutputView;
public class InputController {
private final InputView inputView;
private final OutputView outputView;
public InputController(final InputView inputView, final OutputView outputView) {
this.inputView = inputView;
this.outputView = outputView;
}
public Players getPlayers() {
Players players;
do {
players = readPlayers();
} while (players == null);
return players;
}
public Answer getAnswer(String name) {
Answer answer;
do {
answer = readAnswer(name);
} while (answer == null);
return answer;
}
private Players readPlayers() {
try {
List<String> rawNames = inputView.readNames();
return Players.from(rawNames);
} catch (CustomException exception) {
outputView.printException(exception.getErrorCode());
return null;
}
}
private Answer readAnswer(String name) {
try {
String value = inputView.readAnswer(name);
return Answer.from(value);
} catch (CustomException exception) {
outputView.printException(exception.getErrorCode());
return null;
}
}
}