public class Bowling {
  private static int FRAMES_PER_GAME = 10;
  private static int POSSIBLE_EXTRA_ROLLS = 2;
  private static int MAX_ROLLS = 2 * FRAMES_PER_GAME + POSSIBLE_EXTRA_ROLLS;
  private int[] rolls = new int[MAX_ROLLS];
  private int nextRoll = 0;

  public void roll(int pins)
  {
    rolls[nextRoll++] = pins;
  }

  public int getScore()
  {
    int sum = 0;
    int roll = 0;
    for (int frame = 0; frame < FRAMES_PER_GAME; frame++) {
        if (strike(roll) )  {
          sum += 10 + totalPinsForNextTwoRolls(roll+1);
          roll++;
        } else if (totalPinsForNextTwoRolls(roll) == 10) {
          sum +=10 + rolls[roll+2];
          roll += 2;
        }
        else {
          sum += totalPinsForNextTwoRolls(roll);
          roll += 2;
        }
    }
    return sum;
  }

  private boolean strike(int roll) {
    return rolls[roll] == 10;
  }

  private int totalPinsForNextTwoRolls(int roll) {
    return rolls[roll] + rolls[roll + 1];
  }
}
