-
Notifications
You must be signed in to change notification settings - Fork 550
Expand file tree
/
Copy pathInputView.java
More file actions
49 lines (43 loc) · 1.64 KB
/
InputView.java
File metadata and controls
49 lines (43 loc) · 1.64 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
package BlackJack;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;
public class InputView {
static Scanner sc = new Scanner(System.in);
public static String getPlayerNames() {
System.out.println("게임에 참여할 사람의 이름을 입력하세요.(쉼표 기준으로 분리)");
return sc.next();
}
public String getPlayerChoice(String playerName) {
String choice;
while (true) {
System.out.println(playerName + "는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)");
choice = sc.next();
if (choice.equalsIgnoreCase("y") || choice.equalsIgnoreCase("n")) {
break;
}
if (!choice.equalsIgnoreCase("y") && !choice.equalsIgnoreCase("n")) {
System.out.println("잘못된 입력입니다. 예는 y, 아니오는 n 중 하나를 입력하세요.");
}
}
return choice;
}
public int getMoney(Player player) {
int money = 0;
while (true) {
System.out.println(player.getName() + "의 배팅 금액은?");
try {
money = sc.nextInt();
if (money > 0) {
break;
} else {
System.out.println("배팅 금액은 0보다 커야 합니다. 다시 입력하세요.");
}
} catch (InputMismatchException e) {
System.out.println("잘못된 입력입니다. 숫자를 입력하세요.");
sc.next();
}
}
return money;
}
}