AP CSA 2022 Q1 - Game Class
| <-- Back to AP CSA Exam Solutions | Next to Solution of Q2 (TextBook) - FRQ - 2022 --> |
Solution of Q1 (Game) - Free Response Question - 2022
The original question can be found at: https://apcentral.collegeboard.org/media/pdf/ap22-frq-computer-science-a.pdf
Part (a)- public int getScore()
public int getScore()
{
int score =0;
if (levelOne.goalReached())
{
score = score + levelOne.getPoints();
if (levelTwo.goalReached())
{
score = score + levelTwo.getPoints();
if (levelThree.goalReached())
{
score = score + levelThree.getPoints();
}
}
}
if (isBonus()) score = score *3;
return score;
}
Part (b)- public int playManyTimes(int num)
public int playManyTimes(int num)
{
int maxScore=0;
int score=0;
play();
maxScore = getScore();
for (int i=2; i<=num; i++)
{
play();
score= getScore();
if (score > maxScore) maxScore = score;
}
return maxScore;
}
Java project files (with Runner code):
| <-- Back to AP CSA Exam Solutions | Next to Solution of Q2 (TextBook) - FRQ - 2022 --> |