2.16. Unit 2 Free Response Question (FRQ) Practice

The AP CSA exam has 4 free response questions (FRQs) where you have to write Java code in 1.5 hours. The first FRQ is about Methods and Control Structures using expressions, methods, loops, and if statements. One part of this question usually involves expressions with math operators and calling methods of a given class. Although we have not yet covered enough to complete an FRQ, the following is an adaptation of the 2022 FRQ #1 part a about the points earned in a video game with 3 levels using the class Level. You will try the simplified version of the FRQ in this lesson using just expressions and method calls, and then you will do the complete FRQ part a in the next unit after you learn about if statements.

2.16.1. FRQ Description of Level Class

This question involves simulation of a single-player video game. In the game, a player attempts to complete three levels. A level in the game is represented by the Level class which keeps track of their points in a level and whether they have reached the end or goal of that level.

public class Level
{
    /* The number of points the user has in this level */
    private int points;
    /* Whether the goal of the level has been reached */
    private boolean goal;

    /** Constructor for the Level class */
    public Level(int p, boolean g)
    {
        points = p;
        goal = g;
    }

    /** Returns the number of points (a positive integer) recorded for this level */
    public int getPoints()
    { /* implementation not shown */ }

    /** Returns true if the player reached the goal on this level and returns false otherwise */
    public boolean goalReached()
    { /* implementation not shown */ }

    // There may be instance variables, constructors, and methods that are not shown.
}

2.16.2. FRQ Practice

In this simplified version of this FRQ, you will declare 3 Level objects for the 3 levels of the game and then call their getPoints() methods to calculate the score for the game. The score is calculated by adding the points from each level, but in this version, level 2 points are doubled and level 3 points are tripled.

In the main method, declare 3 objects of the Level class called level1, level2, and level3 with the following points and goals: 100 points and true, 100 points and true, and 200 points and true. Then, calculate the score for the game by adding the points from each level using their getPoints() method, but double the level 2 points and triple the level 3 points.

You have attempted of activities on this page