forked from tpapendieck/ciip-examples
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.
21 lines
569 B
21 lines
569 B
package de.edu.hsfulda.ciip.tdd;
|
|
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
public class BownlingCalculator {
|
|
|
|
public int evaluate(String listOfThrows) {
|
|
int sum = 0;
|
|
Matcher singleDigit = Pattern.compile("\\d").matcher(listOfThrows);
|
|
while (singleDigit.find()) {
|
|
sum += Integer.parseInt(singleDigit.group());
|
|
}
|
|
singleDigit = Pattern.compile("(\\d)/ (\\d)").matcher(listOfThrows);
|
|
while (singleDigit.find()) {
|
|
sum += 10 - Integer.parseInt(singleDigit.group(1)) + Integer.parseInt(singleDigit.group(2));
|
|
}
|
|
return sum;
|
|
}
|
|
|
|
}
|