0% found this document useful (0 votes)
14 views

Ap18 Computer Science A q3

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Ap18 Computer Science A q3

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

2018

AP Computer Science A
Sample Student Responses
and Scoring Commentary

Inside:

Free Response Question 3


RR Scoring Guideline
RR Student Samples
RR 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 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.

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
AP® COMPUTER SCIENCE A
2018 SCORING GUIDELINES

Question 3: Code Word Checker

Class: CodeWordChecker 9 points

Intent: Define implementation of a class to determine if a string meets a set of criteria

+1 Declares header: public class CodeWordChecker implements StringChecker

+1 Declares all appropriate private instance variables

+3 Constructors

+1 Declares headers: public CodeWordChecker(int __, int __, String __) and
public CodeWordChecker(String __)

+1 Uses all parameters to initialize instance variables in 3-parameter constructor

+1 Uses parameter and default values to initialize instance variables in 1-parameter constructor

+4 isValid method

+1 Declares header: public boolean isValid(String __)

+1 Checks for length between min and max inclusive

+1 Checks for unwanted string

+1 Returns true if length is between min and max and does not contain the unwanted string,
false otherwise

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
AP® COMPUTER SCIENCE A
2018 SCORING GUIDELINES

Question 3: Scoring Notes

Class CodeWordChecker 9 points


Points Rubric Criteria Responses earn the point if Responses will not earn the point if
they... they...
Declares header: • omit keyword public • declare class private
public class • declare class static
+1 CodeWordChecker
implements
StringChecker
Declares all appropriate • declare variables as static
+1 private instance • omit keyword private
variables • declare variables outside the class
+3 Constructors
Declares headers: • omit keyword public • declare method static
public • declare method private
CodeWordChecker
(int __, int __,
+1
String __) and
public
CodeWordChecker
(String __)
Uses all parameters to • fail to declare instance variables
initialize instance • initialize local variables instead of
+1
variables in 3- instance variables
parameter constructor • assign variables to parameters
Uses parameter and • initialize instance variables • fail to declare instance variables
default values to to default values when • initialize local variables instead of
+1 initialize instance declared instance variables
variables in 1- • assign variables to parameters
parameter constructor
+4 isValid method
Declares header: • fail to declare method public
public boolean • declare method static
+1
isValid
(String __)
Checks for length • fail to use instance variables
+1 between min and max • fail to declare the method header
inclusive
Checks for unwanted • fail to use instance variables
+1
string • fail to declare the method header
Returns true if length • have incorrect checks for • fail to declare the method header
is between min and max length and/or containment, • fail to return in all cases
+1 and does not contain the but return the correct value • only check one substring location
unwanted string, false based on those checks for containment
otherwise

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
AP® COMPUTER SCIENCE A
2018 SCORING GUIDELINES

Question 3: Code Word Checker

public class CodeWordChecker implements StringChecker


{
private int minLength;
private int maxLength;
private String notAllowed;

public CodeWordChecker(int minLen, int maxLen, String symbol)


{
minLength = minLen;
maxLength = maxLen;
notAllowed = symbol;
}

public CodeWordChecker(String symbol)


{
minLength = 6;
maxLength = 20;
notAllowed = symbol;
}

public boolean isValid(String str)


{
return str.length() >= minLength && str.length() <= maxLength &&
str.indexOf(notAllowed) == -1;
}

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.
Write the complete CodeWordChecker class. Your implementation must meet all specifications and
3A
f
conform to all examples.
Slrr:y ckt.Yer
pvt1 cl.,)) {oJe vJo ,.o\C1e,r,., '"'f'f"'"ls

pri'tei�� i11f ""'11;


pr,vt1i't ,\--t vt--1 ii
rri1-ie �t,(',� .,,, rJ;

f Jt C,k 1,,1,1) Cl,,, Y0 .+ "; ,-d b , S'f•1 c) �


Vlilll:. q
v�l-z ; b
�.,,d � c.
/
p:\ll c.J!,/,,j Ck, V,, ( <J,9 � )
Gi,
l[.,ll -:. i,().
V'I\[-:::
�"'�"' d..,

;.�. be,, le,A •> V,\d (').) d,) j


if ( d r, �-fl-() 4> v,/1 /I;tr.ie.5/l () :,-.,,J Y { ,f �,/,,,,• of v. / H v�J 2
retvr(l :fi�-e i
}
if ( sir, ,Je,,Of
{w11) :> 0} {
rel,,..0 il�e.

Unauthorized copying or reuse of


any part of this page la Illegal.
GO ON TO THE NEXT PAGE.
-15-

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
Write the complete CodeWordChecker class. Your implementation must meet all specifications and
conform to all examples.

�hc... · fok WuJ... (;.,r """) )�}- f,1IVY


)
S-J•j
ii\\/
)
fw

fl.:s. ,.,:,... � {11 ),i �

./1•�. ('vi� -:,,


('/lb..� ·,

.µ, .....
.• :I\� � �I\";

Qg
;r ( sh-, h-, J� {.) � ,. f',"6:>t

rQlvll ,k>1>-.t. ;
�s>-
rtf,.,-/1 �/�;

Unauthorlied copying or reuse of


any part of this pago la Illegal.
GO ON TO THE NEXT PAGE.
-15-

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
Write the complete CodeWordChecker class. Your implementation must meet all specifications and
conform to all examples.

\J \J\. ,\i._

(\ r) ..\. �
\/ ''· •:. '., J

( \ '\ <' ,. l. t ( ( i:_ r.. >.. ... , -:1 / � fl. � 11


t 1

r' I 't. '


)
/\..c,l ; fl "
;

l.,l, '- \.,i:>c,\ e 6\-1" I':., \J � \i� LG( ( 1 rA f ) {_


\) 0
6
'\..\'-.l1,L,.l,1,�,�l��l) L. t'\ -1/,l..l)':>t->,./t',)
0

\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- .\,.\,·,,�

Unauthorized copying or reuse of


any part of thl• page Is Illegal.
GO ON TO THE NEXT PAGE.

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
AP® COMPUTER SCIENCE A
2018 SCORING COMMENTARY

Question 3

Overview

This question tested the student's ability to:

• Write program code to define a new type by creating a class;


• 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
statements.

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

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
AP® COMPUTER SCIENCE A
2018 SCORING COMMENTARY

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.

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.

You might also like