-
Notifications
You must be signed in to change notification settings - Fork 590
Expand file tree
/
Copy pathPlayer.java
More file actions
41 lines (31 loc) · 1.11 KB
/
Player.java
File metadata and controls
41 lines (31 loc) · 1.11 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
package baseball;
import camp.nextstep.edu.missionutils.Console;
import java.util.ArrayList;
import java.util.List;
import static baseball.InputException.validatesNumber;
public class Player {
private final List<Integer> inputNumberList;
public Player() {
this.inputNumberList = new ArrayList<>();
}
public void playerInputNumber() { // 사용자 입력 메서드
System.out.print("숫자를 입력해주세요 : ");
String input = Console.readLine();
validatesNumber(input);
inputNumberList.clear(); // 이전 입력값을 비우기
for (char ch : input.toCharArray()) { // 입력받은 숫자를 List에 저장
inputNumberList.add(Character.getNumericValue(ch));
}
}
public List<Integer> getInputNumberList(){
return this.inputNumberList;
}
// 게임 재시작 여부를 결정하는 메서드
public String inputReplay(){
String inputReplay = Console.readLine();
if (!inputReplay.equals("1") && !inputReplay.equals("2")) {
throw new IllegalArgumentException("잘못된 입력입니다. 1 또는 2를 입력하세요.");
}
return inputReplay;
}
}