-
Notifications
You must be signed in to change notification settings - Fork 906
Expand file tree
/
Copy pathNumbersBaseball.java
More file actions
54 lines (42 loc) · 1.36 KB
/
NumbersBaseball.java
File metadata and controls
54 lines (42 loc) · 1.36 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
package numbersBaseball;
import java.util.ArrayList;
public class NumbersBaseball {
public static int compareTo(ArrayList<Integer> compareNum){
// 초기화
int strike = 0, ball = 0;
for (int i = 1; i <= 3; i++) {
int cur = compareNum.get(i-1);
if(InputView.check[cur] != 0 && InputView.check[cur] == i) {
strike++;
continue;
}
if(InputView.check[cur] != 0) {
ball++;
}
}
System.out.println(ResultView.scoreResult(strike, ball));
return strike;
}
public void game(int[] randomNum) {
int strike = 0, ball = 0;
InputView.makeRandomNumber(randomNum);
while(strike != 3) {
System.out.print("숫자를 입력해 주세요 : ");
int inputNum = InputView.inputNumber();
ArrayList<Integer> inputList = InputView.splitNumber(inputNum);
if(!InputView.validateNumber(inputList)) continue;
strike = compareTo(inputList);
}
}
public NumbersBaseball() {
int[] randomNum = new int[3];
while (true) {
game(randomNum);
ResultView.ending();
if(InputView.inputNumber() == 2) return;
}
}
public static void main(String[] args) {
new NumbersBaseball();
}
}