2022 FRQ Problem #1 part a

First Attempt

public int getScore {
    if (goalReached(levelOne) = true) {
        int score = 200;
        if (goalReached(levelTwo) = true) {
            int score = score+100;
            if (goalReached(levelThree) = true) {
                int score = score+500;
                if (isBonus() = true) {
                    int score = score*3;
                }
            }
        }
    }
}

Comments

  • I should define score at the very beginning
  • Bonus game has nothing to do with what level you completed (misread question)
  • getscore needs to have two parenthesis -> getscore()
  • levelOne and the other levels are objects
  • goalReached is a function
  • I don't need to add the actual pt value, just use the getPoints parameter
    • my syntax wasn't right either. need to practice this and get out of the python mindset
  • forgot to return score

Solution

public int getScore() 
{
  int score = 0;
  if (levelOne.goalReached())
  {
    score = levelOne.getPoints();
    if (levelTwo.goalReached())
    {
      score += levelTwo.getPoints();
    if (levelThree.goalReached())
    {
      score += levelThree.getPoints();
    }
  }
}
if (isBonus())
{
score *= 3;
}

2022 FRQ Problem #1 part b

public int playManyTimes(num) {
    int max = 0;
    for (int i = 0; i<num;i++) {
        play();
        int score = getScore();
        if (score > max) {
            max = scorel
        }
    }
}
return max;

Comments

  • Definitely did better than part a
  • return max needs to be inside playManyTimes
  • num needs to be defined as an integer

Solution

public int playManyTimes(int num) {
    int max = 0;
    for (int i = 0; i<num;i++) {
        play();
        int score = getScore();
        if (score > max) {
            max = scorel
        }
    }
    return max;
}