AP
®
COMPUTER SCIENCE A
2018 SCORING COMMENTARY
Question 1 (continued)
Sample: 1B
Score: 5
In
part (a) hopDistance is called correctly, and the returned result is used to adjust a variable representing the
frog’s position. An improperly structured assignment operator is used. However, this is a nonpenalized error, and
the response earned point 1. Because an incorrect loop terminating condition allows for the frog’s position to be
updated more than maxHops times, the response did not earn point 2. Point 3 was earned when a conditional
was used to determine if the frog’s position has reached or exceeded goalDistance. Because the response
does not include a check to determine if the frog’s position is less than the starting position, the response did not
earn point 4. For multiple reasons, the logic of the return statement is incorrect. First, the goalDistance check
occurs outside of the loop, so the response could return an incorrect result after the goal has been reached.
Second, there is no determination as to whether the distance is less than the starting position. As a result the
response could return an incorrect result after a negative position has been achieved. For either of these reasons,
the response did not earn point 5. Part (a) earned 2 points.
In part (b) simulate is called more than num times due to an incorrect terminating condition within the loop.
T
herefore, the response did not earn point 6. Point 7 was earned because a variable is initialized and correctly
used to count true results. The variable is correctly cast as a double and is divided by a variable containing
the parameter value, so the response earned point 8. The calculated value is returned, and the response earned
point 9. Part (b) earned 3 points.
Sample: 1C
Score: 3
In part (a) hopDistance is called, and the returned result is used to adjust a variable representing distance.
Because hopDistance is a parameter-less method, the missing parenthesis is a nonpenalized error. Therefore,
the response earned point 1. For several reasons, the response does not include the required elements to earn
point 2. First, the terminating condition of the loop does not refer to maxHops but instead refers to a variable
that is neither declared nor initialized. Second, the comparison operator within the terminating condition of the
loop allows hopDistance to be called more than maxHops times. Finally, the variable used to adjust distance
is neither declared nor initialized. For any of these reasons, the response did not earn point 2. Because the
response does not refer to goalDistance in the attempt to determine if the frog reached the goal, the response
did not earn point 3. The response does not include a check to determine if the frog’s position is less than the
starting position, so the response did not earn point 4. Because the starting position check is omitted, the
response will not always return a correct value. Therefore, the response did not earn point 5. Part (a) earned
1 point.
In part (b) the response did not earn point 6 because simulate is called incorrectly by including a parameter in
t
he method call. A properly initialized variable is used to accumulate a count of true values, so the response
earned point 7. The calculation of the proportion of successful simulations is incorrectly cast as a double, so
the response did not earn point 8. The calculated result is returned. Therefore, the response earned point 9.
Part (b) earned 2 points.
© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.