AP
®
Computer Science A 2021 Scoring Commentary
© 2021 College Board.
Visit College Board on the web: collegeboard.org.
Question 2
Overview
This question tested the student’s ability to:
• Write program code to define a new type by creating a class.
• W
rite program code to create objects of a class and call methods.
• Write program code to satisfy methods using expressions and conditional statements.
Stu
dents were asked to design the class CombinedTable, which represents a table composed of two single
tables pushed together. The students were given a partial definition of the class SingleTable, which
represents a table at a restaurant, to be used in their CombinedTable class design. Students were expected to
demonstrate an understanding of class constructor and method header syntax. Additionally, students were
expected to determine the data types and instance variables needed to track the information shown in the
example. Students were then expected to correctly declare, initialize, access, and generate the appropriate values
from their data members. Students were expected to properly protect the data members by declaring them as
private and properly define the methods canSeat and getDesirability. Students had to recognize that
they could not compute and store the desirability value in the constructor because the design of SingleTable
allowed for a table view quality to change at any time; getDesirability always had to reflect the latest
values of the SingleTable view quality.
Sample: 2A
Score: 9
Point 1 was earned because the response correctly declares the class header and constructor header. The
response correctly names the constructor and provides two SingleTable parameters. Both the class and the
constructor are declared as public. Point 2 was earned because the response declares two SingleTable
instance variables. The view quality of a constituent table may change after a CombinedTable is
constructed. The point verifies that the design of the response supports this by requiring SingleTable
instance variables. The instance variables must be declared as private. Point 3 was earned because the
constructor initializes the instance variables with parameter values. The point tests not only the assignment of
a parameter to an instance (or local) variable but also that the assignment involves consistent types. Point 3
does not assess the usefulness of the values assigned. Point 4 was earned because the response correctly
declares the header for the canSeat method. The method must return a boolean, take a single int
parameter, and have a public access specifier. Point 5 was earned because the response calls the
getNumSeats method on SingleTable objects. The response calls the method correctly with instance
variables a and b. In the response, the call to getNumSeats occurs in the canSeat method. Point 6 was
earned because the response chooses the correct return value, based on the correct comparison, with a correct
seat calculation. The point evaluates the logic of the canSeat method. To earn the point, both the calculation
of available seats and the returned value must be correct. Point 7 was earned because the header for the
getDesirability method is correct. To earn the point, the method must be declared as public, must
have a return type of double, and must have an empty parameter list. Point 8 was earned because the
response correctly calls both the getHeight and getViewQuality methods on SingleTable objects.
The response calls both methods on SingleTable instance variables in the getDesirability method.
The missing () on the parameter-less method invocation (on the fourth call to getViewQuality) is one of
the minor errors for which no penalty is assessed. (The "No Penalty" category on page 1 of the Scoring
Guidelines contains a complete list of these errors.) Point 9 was earned because the response correctly
computes the average desirability of the CombinedTable. The point evaluates the calculation only. To earn
the point, a response must compare the heights of the SingleTable objects, choose the correct formula, and
calculate the desirability accordingly.