You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
552 B
17 lines
552 B
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
public class BowlingGameCalculator {
|
|
|
|
private static final Pattern SINGLE_VALUE_PATTERN = Pattern.compile("\\d");
|
|
private static final int INITIAL_SCORE_VALUE = 0;
|
|
|
|
public int score(String playerResult) {
|
|
Matcher singleDigit = SINGLE_VALUE_PATTERN.matcher(playerResult);
|
|
int playerScore = INITIAL_SCORE_VALUE;
|
|
while (singleDigit.find()) {
|
|
playerScore += Integer.parseInt(singleDigit.group());
|
|
}
|
|
return playerScore;
|
|
}
|
|
}
|