-
Notifications
You must be signed in to change notification settings - Fork 906
Expand file tree
/
Copy pathBallCountService.java
More file actions
30 lines (22 loc) · 942 Bytes
/
BallCountService.java
File metadata and controls
30 lines (22 loc) · 942 Bytes
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
package gameResult;
import utils.ConstantUtils;
public class BallCountService {
public int ballCount(int [] answer, int [] input) {
int totalBall = 0;
for(int answerIdx = 0; answerIdx < ConstantUtils.GAME_NUM_LENGTH; ++answerIdx){
totalBall += countInputBallCompareAnswerElement(answer[answerIdx], input, answerIdx);
}
return totalBall;
}
int countInputBallCompareAnswerElement(int answer, int [] input, int answerIdx) {
int ballByOneAnswerCount = 0;
for(int inputIdx = 0; inputIdx < ConstantUtils.GAME_NUM_LENGTH; ++inputIdx){
ballByOneAnswerCount += checkBall(answer, input[inputIdx], answerIdx, inputIdx);
}
return ballByOneAnswerCount;
}
int checkBall(int answerElement, int inputElement, int answerIdx, int inputIdx){
if(answerElement == inputElement && answerIdx != inputIdx) return 1;
return 0;
}
}