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

  1. package de.edu.hsfulda.ciip.tdd;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4. public class BownlingCalculator {
  5. public int evaluate(String listOfThrows) {
  6. int sum = 0;
  7. Matcher singleDigit = Pattern.compile("\\d").matcher(listOfThrows);
  8. while (singleDigit.find()) {
  9. sum += Integer.parseInt(singleDigit.group());
  10. }
  11. singleDigit = Pattern.compile("(\\d)/ (\\d)").matcher(listOfThrows);
  12. while (singleDigit.find()) {
  13. sum += 10 - Integer.parseInt(singleDigit.group(1)) + Integer.parseInt(singleDigit.group(2));
  14. }
  15. return sum;
  16. }
  17. }