forked from woowacourse-precourse/java-baseball-6
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathApplication.java
More file actions
49 lines (40 loc) · 1.59 KB
/
Application.java
File metadata and controls
49 lines (40 loc) · 1.59 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 baseball;
import camp.nextstep.edu.missionutils.Randoms;
import camp.nextstep.edu.missionutils.Console;
import java.util.Scanner;
public class Application {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("숫자 야구 게임을 시작합니다.");
int[] randoms = new int[3];
RandomNumber random = new RandomNumber();
random.randomNumber(randoms);
while (true) {
try {
System.out.print("숫자를 입력해주세요 : ");
String answer = Console.readLine();
ExceptionHandler exceptionHandler = new ExceptionHandler();
exceptionHandler.checkValid(answer);
String[] answers = new String[3];
for (int i = 0; i < 3; i++) {
answers[i] = answer.substring(i, i + 1);
}
Count count = new Count();
count.countStrike(randoms, answers);
count.countBall(randoms, answers);
count.printCount();
if (count.getStrikes() == 3) {
System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요.");
int option = scanner.nextInt();
if (option == 2) {
return;
} else {
random.randomNumber(randoms);
}
}
} catch (IllegalArgumentException e){
throw e;
}
}
}
}