Ap18 Computer Science A q3
Ap18 Computer Science A q3
AP Computer Science A
Sample Student Responses
and Scoring Commentary
Inside:
© 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 official online home for the AP Program: apcentral.collegeboard.org
AP® COMPUTER SCIENCE A
2018 SCORING 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 access 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 Penalty
o Extraneous code with no side-effect (e.g., valid precondition check, no-op)
o Spelling/case discrepancies where there is no ambiguity*
o Local 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 Common mathematical symbols used for operators (× • ÷ < > <> ≠)
o [] vs. () vs. <>
o = instead of == and vice versa
o length/size confusion 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
unambiguously inferred from context, for example, “ArayList” instead 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.
+3 Constructors
+1 Declares headers: public CodeWordChecker(int __, int __, String __) and
public CodeWordChecker(String __)
+1 Uses parameter and default values to initialize instance variables in 1-parameter constructor
+4 isValid method
+1 Returns true if length is between min and max and does not contain the unwanted string,
false otherwise
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.
.µ, .....
.• :I\� � �I\";
Qg
;r ( sh-, h-, J� {.) � ,. f',"6:>t
rQlvll ,k>1>-.t. ;
�s>-
rtf,.,-/1 �/�;
\J \J\. ,\i._
(\ r) ..\. �
\/ ''· •:. '., J
\f\ \\ t-;,.l.\,� (✓
\ ·( t. � 1\ f, • \ ,... \. ,;_ C j
'· : C) ) I,. I.� {{l ,lc.�l,;1...l� • f-(.)�',\".1'1.tJ·J \-'v·\·) [�.
\ ·\- ( S·\ , • �- -:. , ·' �I , i lt ) , "' "�,+- . , ,, f" ) ) . , '!/ I'•· , Al,I �
O
\'\.'._1 ..., ,r- .\,.\,·,,�
Question 3
Overview
Students were asked to design the class CodeWordChecker so that it implements the method isValid in
the given interface, StringChecker. In addition to demonstrating an understanding of class constructors
and method header syntax, students had to correctly declare, initialize, access, and update instance variables.
Students were expected to properly encapsulate their data members by declaring them as private and to
properly define the interface method isValid and expose it by declaring the method public. Students also
had to recognize that two constructors needed to be included in order to conform to the examples given.
This question primarily addressed the fundamental skill of how to create a class so that it adheres to a specific
interface. However, there was also a logic component required to make the class operational. The students had
to demonstrate an understanding of how to control the visibility of class elements so that the language would
enforce the separation. The internal representation had to be hidden and inaccessible from the client, and the
interface method had to be defined and made publicly available.
Implementing the isValid method required students to find the length of a string and check if it was within
a specified range and also to determine if one string was a substring of another. Students then needed to return
an appropriate Boolean value based on the result of their logic.
Sample: 3A
Score: 8
In this solution point 1 was earned because the header is correctly declared. Point 2 was earned because all
appropriate private instance variables are declared. Point 3 was earned because the 3-parameter
constructor and the 1-parameter constructor headers are declared. Point 4 was earned because each of the
parameters is used to initialize the instance variables. Point 5 was earned because the instance variables for
minimum and maximum code length are initialized to 6 and 20, respectively, and the String parameter is
used to initialize the String instance variable. In the solution for the isValid method, point 6 was earned
because the header is correctly declared. Point 7 was earned because the length of the String parameter is
correctly compared to the minimum and maximum lengths. Point 8 was not earned because the value returned
by the indexOf method is checked using > 0 rather than > 0. Point 9 was earned because the conditional
statement returns false when given an invalid length, false when the instance variable is found in the
String parameter, and true otherwise.
Sample: 3B
Score: 6
In this solution point 1 was not earned because the header uses extends StringChecker. Point 2 was
earned because all appropriate private instance variables are declared. Point 3 was not earned because the
response fails to declare the 1-parameter constructor. Point 4 was earned because each of the parameters is
used to initialize the instance variables. Point 5 was not earned because the response fails to implement the
Question 3 (continued)
1-parameter constructor. In the solution for the isValid method, point 6 was earned because the header is
correctly declared. Point 7 was earned because the length of the String parameter is determined to be
between the minimum and maximum lengths, inclusive. Point 8 was earned because the response checks for
the unwanted string by calling the indexOf method and comparing it to -1. Point 9 was earned because the
conditional statement returns false when given an invalid length, false when the instance variable is
found in the String parameter, and true otherwise.
Sample: 3C
Score: 2
In this solution point 1 was not earned because the header incorrectly includes parameters. Point 2 was not
earned because no private instance variables are declared. Not declaring instance variables also resulted in
the loss of points 4, 5, 7, and 8. Point 3 was not earned because the response fails to declare the 1-parameter
constructor. Point 4 could have been earned if instance variables had been declared. In the solution for the
isValid method, point 6 was earned because the header is correctly declared. Point 7 could have been
earned because the length of the String parameter is compared to the minimum and maximum lengths.
Point 8 was not earned because the instance variables are not declared. In addition, the point would not have
been earned because the response, while traversing the String parameter one index at a time, fails to test
the last occurrence of the substring. Point 9 was earned because the logic for finding an invalid code word is
correct.