2018
AP Computer Science A
Sample Student Responses
and Scoring Commentary
Inside:
Free Response Question 1
Scoring Guideline
Student Samples
Scoring Commentary
© 2018 The College Board. College Board, Advanced Placement Program, AP, AP Central, and the acorn logo
are registered trademarks of the College Board. Visit the College Board on the Web: www.collegeboard.org.
AP Central is the ocial online home for the AP Program: apcentral.collegeboard.org
AP
®
COMPUTER SCIENCE A
2018 SC
ORING GUIDELINES
Apply the question assessment rubric first, which always takes precedence. Penalty points can only be
deducted in a part of the question that has earned credit via the question rubric. No part of a question (a, b, c)
may have a negative point total. A given penalty can be assessed only once for a question, even if it occurs
multiple times or in multiple parts of that question. A maximum of 3 penalty points may be assessed per
question.
1-Point Penalty
v) Array/collection acce
ss confusion ([] get)
w) Extraneous code that causes side-effect (e.g., printing to output, incorrect precondition check)
x) Local variables used but none declared
y) Destruction of persistent data (e.g., changing value referenced by parameter)
z) Void method or constructor that returns a value
No Pe
nalty
o Extraneous code with no side-effect (e.g., valid precondition check, no-op)
o Spelling/case discrepancies where there is no ambiguity*
o L
oca
l variable not declared provided other variables are declared in some part
o private or public qualifier on a local variable
o Missing public qualifier on class or constructor header
o Keyword used as an identifier
o C
ommon mathematical symbols used for operators (× • ÷ < > <> ≠)
o [] vs. () vs. <>
o = instead of == a
nd vice versa
o length/size conf
usion for array, String, List, or ArrayList; with or without ( )
o Extraneous [] when referencing entire array
o [i,j] instead of [i][j]
o Extraneous size in array declaration, e.g., int[size] nums = new int[size];
o Missing ; where structure clearly conveys intent
o Missing { } where indentation clearly conveys intent
o Missing ( ) on parameter-less method or constructor invocations
o Missing ( ) around if or while conditions
*Spelling and case discrepancies for identifiers fall under the “No Penalty” category only if the correction can be
unam biguously inferred from context, for example, “ArayListinstead of “ArrayList”. As a counterexample, note
that if the code declares int G=99, g=0;, then uses while (G < 10) instead of while (g < 10),
the context does not allow for the reader to assume the use of the lower case variable.
© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
AP
®
COMPUTER SCIENCE A
2018 SCORING GUIDELINES
Question 1: Frog Simulation
Part (a) simulate 5 points
Intent: Simulate the distance traveled by a hopping frog
+1
Calls hopDistance and uses returned distance to adjust (or represent) the frog’s position
+1
Initializes and accumulates the frog’s position at most maxHops times (must be in context of a
loop)
+1
Determines if a distance representing multiple hops is at least goalDistance
+1 Determines if a distance representing multiple hops is less than starting position
+1
Returns true if goal ever reached, false if goal never reached or position ever less than
starting position
Part (b) runSimulations 4 points
Intent: Determine the proportion of successful frog hopping simulations
+1
Calls simulate the specified number of times (no bounds errors)
+1
Initializes and accumulates a count of true results
+1
Calculates proportion of successful simulations using double arithmetic
+1 Returns calculated value
© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
AP
®
COMPUTER SCIENCE A
2018 SCORING GUIDELINES
Question 1: Scoring Notes
Part (a)
simulate
5 points
Points Rubric Criteria Responses earn the point if they... Responses will not earn the point if they...
+1
Calls hopDistance
and uses returned
distance to adjust (or
represent) the frog’s
use hopDistance() as a
position, like
hopDistance() < 0
only use hopDistance() as a
count, like hopDistance() <
maxHops
+1
Initializes and
accumulates the frog’s
position at most
maxHops times (must
do not use a loop
+1
Determines if a
distance representing
multiple hops is at
least
use some number of hops *
hopDistance() as the
frog’s final position
+1
distance representing
multiple hops is less
than starting position
+1
Returns true if goal
ever reached, false
if goal never reached
or position ever less
have checks for all three
conditions and correct return
logic based on those checks,
even if a check did not earn a
point
do not check all three conditions
on
ly check for goalDistance after
the loop
only check for starting position after
the loop
Part (b)
runSimulations
4 points
Points Rubric Criteria Responses earn the point if they... Responses will not earn the point if they...
+1
Calls simulate the
specified number of
times (no bounds
do not use the result of calling
simulate
do not use a loop
+1
accumulates a count of
results
initialize the count inside a loop
do not use a loop
+1
C
alculates proportion
of successful
simulations using
double arithmetic
perform the correct
calculation on an
accumulated value, even if
there was an error in the
accumulation
fail to divide by the parameter
+1
Returns calculated
value
calculate values using nonnumeric
t
ypes
return a count of simulations
© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
AP
®
COMPUTER SCIENCE A
2018 SCORING GUIDELINES
Question 1: Frog Simulation
Part (a)
public boolean simulate()
{
int position = 0;
for (int count = 0; count < maxHops; count++)
{
position += hopDistance();
if (position >= goalDistance)
{
return true;
}
else if (position < 0)
{
return false;
}
}
return false;
}
Pa
rt (b)
public double runSimulations(int num)
{
int countSuccess = 0;
for (int count = 0; count < num; count++)
{
if(simulate())
{
countSuccess++;
}
}
return (double)countSuccess / num;
}
These canonical solutions serve an expository role, depicting general approaches to solution. Each reflects only one
instance from the infinite set of valid solutions. The solutions are presented in a coding style chosen to enhance readability
and facilitate understanding.
© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
ir
(i,J    <

x
 
1
 





Q)
f





e e
n e
p
a












7









  

 

  

 -

 

1

 
,t

+
(



   
   

© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
  
f


  
     
    
    

r  
   


    
    t
" \ "   i
 

0;   ; 

 
J
1
(J
o
blt) 
 
 
 

© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.



  







 


*/
  
L
  
  

 t t 

'[





j


  


© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
 -

   



  
oo, 
 
    
-
    
  
/ * *   
*

    
*I
   
l
  
 j
J
0



fc(L,i 

t

 
GO ON 

© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
    
,A
 

  

 

  


  


© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
I
k=O; 






r

   
 
      
    
    
  
I**   



   

   
L -Q·
'f





'
,
t
re t
 
  
 

© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
AP
®
COMPUTER SCIENCE A
2018 SC
ORING COMMENTARY
Question 1
Overview
This question tested the student's ability to:
Write program code to create objects of a class and call methods; and
Write program code to satisfy methods using expressions, conditional statements, and iterative
s
tatements.
Students were provided with the specifications of the FrogSimulation class. The FrogSimulation class
e
ncapsulates a simulation of a frog hopping in a straight line. It contains two private integer instance variables,
goalDistance and maxHops, which represent the distance in inches from the starting point to the goal and
the maximum number of hops allowed to reach the goal. It also contains a private method, hopDistance,
which returns an integer representing the distance in inches to be moved when the frog hops. Implementation for
this method was not shown.
In part (a) students were asked to write the FrogSimulation method simulate, which determines whether
a f
rog is successful in reaching goalDistance. Students were required to use the private method
hopDistance within the context of a loop to update an initialized variable representing the frog's position. The
loop iterates until one of the following conditions becomes true:
The frog has reached or passed the goal, in which case a value of true is immediately returned.
The frog has reached a negative position, in which case a value of false is immediately returned.
A frog has taken maxHops hops without reaching the goal, in which case a value of false is returned.
In part (b) students were asked to write the FrogSimulation method runSimulations(int num), which
us
es a loop to call the simulate method num times. Each time simulate returns true, a previously
initialized variable is incremented. The method returns a decimal value representing the proportion of simulations
in which the frog successfully reached or passed the goal.
Sa
mple: 1A
Score:
9
In p
art (a) the response earned point 1 by adjusting a variable representing the frog’s position with the result of a
correct call to hopDistance. The variable is properly initialized and is updated within a loop that iterates no
more than maxHops times. Therefore, the response earned point 2. The response uses conditional statements to
correctly determine if the frog’s position is greater than or equal to goalDistance or if the frog’s position is
less than the starting position. For this reason, the response earned both points 3 and 4. All of the conditional
statements exist within the context of the loop. This allows the response to correctly return true if the goal is
met and false otherwise. As a result the response earned point 5. Part (a) earned 5 points.
In part (b) point 6 is earned because the response implements a loop to correctly call simulate exactly num
times. A properly initialized variable is used to accumulate a count of true results, so the response earned
point 7. The variable is correctly cast to a double value prior to being divided by the parameter. For this reason
the response earned point 8. The calculated value is returned, and the response earned point 9. Part (b) earned
4 points.
© 2018 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
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.