0% found this document useful (0 votes)
24 views13 pages

Ap18 Computer Science A q2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views13 pages

Ap18 Computer Science A q2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

2018

AP Computer Science A
Sample Student Responses
and Scoring Commentary

Inside:

Free Response Question 2


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 2: Word Pair

Part (a) WordPairList 5 points


Intent: Form pairs of strings from an array and add to an ArrayList

+1 Creates new ArrayList and assigns to allPairs

+1 Accesses all elements of words (no bounds errors)

+1 Constructs new WordPair using distinct elements of words

+1 Adds all necessary pairs of elements from word array to allPairs

+1 On exit: allPairs contains all necessary pairs and no unnecessary pairs

Part (b) numMatches 4 points


Intent: Count the number of pairs in an ArrayList that have the same value

+1 Accesses all elements in allPairs (no bounds errors)

+1 Calls getFirst or getSecond on an element from list of pairs

+1 Compares first and second components of a pair in the list

+1 Counts number of matches of pair-like values

Question-Specific Penalties

-1 (z) Constructor returns a value

© 2018 The College Board.


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

Question 2: Scoring Notes

Part (a) WordPairList 5 points


Points Rubric Criteria Responses earn the point if they... Responses will not earn the point if they...
• allPairs = new • initialize a local variable that is never
Creates new ArrayList(); assigned to allPairs
+1 ArrayList and • allPairs = new
assigns to allPairs ArrayList<>();
• this.allPairs = ...
Accesses all elements
+1 of words (no bounds
errors)
Constructs new
WordPair using
+1
distinct elements of
words
Adds all necessary • have a loop bounds error • improperly add to an ArrayList,
pairs of elements from • add unnecessary pairs e.g., allPairs.get(i) = x;
+1
word array to • only add consecutive pairs
allPairs (words[i], words[i+1])
On exit: allPairs • improperly add to an • add pairs (i, i) or (i, j) where i > j
contains all necessary ArrayList, e.g.,
+1 allPairs.get(i) = x;
pairs and no
unnecessary pairs • have a loop bounds error
Part (b) numMatches 4 points
Points Rubric Criteria Responses earn the point if they... Responses will not earn the point if they...
Accesses all elements • access elements of allPairs as
+1 in allPairs (no array elements (e.g., allPairs[i])
bounds errors)
Calls getFirst or
getSecond on an
+1
element from list of
pairs
Compares first and • compare using ==
+1 second components of
a pair in the list
Counts number of • fail to initialize the counter
+1 matches of pair-like
values

Return is not assessed in part (b).

© 2018 The College Board.


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

Question 2: Word Pair

Part (a)

public WordPairList(String[] words)


{
allPairs = new ArrayList<WordPair>();

for (int i = 0; i < words.length-1; i++)


{
for (int j = i+1; j < words.length; j++)
{
allPairs.add(new WordPair(words[i], words[j]));
}
}
}

Part (b)

public int numMatches()


{
int count = 0;

for (WordPair pair: allPairs)


{
if (pair.getFirst().equals(pair.getSecond()))
{
count++;
}
}
return count;
}

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.
Complete the WordPairList constructor below.

/** Constructs a WordPairList object as described in part (a).


* Precondition: words. length >= 2
*/
public WordPairList(String[) words) f
�Vrl\�14+ < Word. Poir > p = rtQM k\,1ro]'L:&i" L Worol f>o.;r > ( J �
jo( ( 11-lt ;=o ; I< �orolA. � ;1 i•�,-/); it ➔) f
tor (;,.,tj:::.i+I � jL w11rola.&,.,�.+h;.
J
;t)f

p, o..olol ( V\MIV Wo1-ol Po. ,Y- ( words Li J J i.,w"rcls C.j J )) j

J
'

Part (b) begins on page 12

Unauthorized copying or reuse of


any parl of this page Is Illegal.
GO ON TO THE NEXT PAGE.
-11-

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
2A b
Complete method numMatches below.
I** Returns the number of matches as described in part (b).
*I
public int numMatches() l
ii'\\ CO(AYl"t .::. 0 j

foY (;\At i=O j jL'Oillp01;1.g ,s(� l) _:, .,'-rt) r.


WonA Po.:r U!.\l\"P = °'.II P(.)lil'S ., j,Q,-i- ( I) ;
;f((-(j,,111"r· yir;1st U). 4w,b (t.11w,p ,Jtt u.co,,.,_£.f lJ)) f
Wv10t -r -r ..i

}
}

Unauthorized copying or reuse of


any part of this page Is Illegal.
GO ON TO THE NEXT PAGE.
-13-

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
Complete the WordPairList constrnctor below.

I** Constructs a wora PairList object as described in part (a)


.
* p1econ d'1tion:
.
words. length >:= 2
2B�
*I
ublic WordPairLis ( tring II words)
{, :�
M: 1,./ /+vruy Lisi [ J �
lf-rray _Lisl--ilJo,:d Ic, 's 7 / d �
fo,(,t-=O; i t_ vo,-d�. leflS'}-11; if+-)

f ,
t l r:.;on.k /e,r1yM; k.H)
I

{or(,k "'- 1-j


t .I
' I

W.Y-ds- [/ J, [ le JJ ,
V6'r'd fc.i'1 fe fY/p = (Y;,1/
/,ifJ,Pco'r ( J
/,St< . o.dd. (1-ori p);
�-

3
, fot- {Worrl for1f' pa;�: (1if)
t
0i II /bl�. aJd {fa, rsj_/

Part (b) begins on page 12

Unaulhorlzed copying or reuse of


any part of this page Is Illegal.
GOONTOTHENEXTPAGE.
-11-

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
2B b
Complete method numMatches below.
I**Returns the number of matches as described in part (b).
*/
public int numMatches()

E ,_ }
, .:::::. o
I nr }')>cr·c)1e� J

f-or-l1,nf- / ::.o; .
II
f L"Q{ flr/rs, 5lze.{ )j ,· fl)

( r CafI lb rs' � fD) , gef


�-
fi'rs-/(), eQ_ ,c:Js{-
c
I

Cl I I ft'J1'r5. 9c -1- (,) .9e-f-�co>1d C)))


f>pk/£6 I- +-;
� \ !

Unauthorized copying or reuse of


any part of this page Is Illegal.
GO ON TO THE NEXT PAGE.
-13-

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
zctL,
Complete the WordPairList constructor below.
I

/** Constructs a WordPairList object as described in part (a).


* Precondition: words. length >= 2

rfic •:
*/
rdPairList{Strin: I � •::��\.�I; \� �t)

·o(l'1At )(:Oi

!_ .�JuC1t . . .J. t)
f of (L11t j -:. It+ 1 � i L w�r., ·�'I '
J(

l ().II p Q.·,ri. 11.d J l• W'orJ p01irL1<,, l) 1

J
}
}

Part (b) begins on page 12

Unauthorized copying or reuse of


any part of this page Is Illegal.
GO ON TO THE NEXT PAGE.
-11-

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
Complete method numMatches below.
. I** Returns lhe
• number of mac
t 11es as descnbed in part (b).

'
*I
public int numMatches () 2.Cb
L ·,11t r,v.tlf\AW,r}.�} :: oi

i :. i i L "II r�.rr. r:uO � i t ti)


f.ar lint 0

l ++ i)
fG ( lint l :. O j LL• 11 f" ;(i.\itf(/i
l if ( i ! :: L)
t I f-(_{p.11 f.;{\ . ie1 li \) • e, �qlJ (•tlf-\fl , j!t(�))
J 11•'11 M.�ft�t) -t t}

Unauthorized copying or reuse of


any part of this page Is Illegal.
GO ON TO THE NEXT PAGE.
-13-

© 2018 The College Board.


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

Question 2

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 create, traverse, and manipulate elements in 1D array or ArrayList objects.

Students were asked to write a constructor and a method of the WordPairList class. In writing the
constructor, students were expected to access an array of strings in order to populate an ArrayList of
WordPair objects. Students were also expected to traverse the list of objects in order to count how many
elements met a specified requirement. A provided WordPair class is used to represent pairs of words extracted
from the array.

In part (a) the students were asked to write a constructor for the WordPairList class. Students needed to
recognize that the ArrayList instance variable must be constructed before elements can be added. To
populate the list, the students were expected to write a loop structure to pair each element from the words array
parameter with each of the subsequent elements in the array. Students were expected to construct a WordPair
object from each of the paired elements and add each WordPair object to the allPairs instance variable.

In part (b) students were expected to access all the elements of allPairs to count how many WordPair
elements consisted of pairs of matching strings. Students were expected to call the WordPair methods
getFirst and getSecond to access each word component in the pair. To compare the words, students were
expected to use appropriate methods of the String class, such as equals or compareTo. To count the
number of matching words, students were expected to declare and initialize an accumulator before their loop
structure and increment it only when a match was found. While the method was required to return a value, the
return of the accumulator was not assessed in this question.

Sample: 2A
Score: 9

In part (a) the response earned point 1 because it creates a new ArrayList as a local variable and then assigns
it to allPairs after populating the list. Point 2 was earned by accessing all elements of the words array in
the nested for loops with no bounds errors. The response earned point 3 by correctly constructing a new
WordPair object using two distinct elements of words. Points 4 and 5 were earned by correctly adding all
necessary pairs of elements from the word array to allPairs. Within the nested loops, the inner loop control
variable is initialized to be one greater than the outer loop control variable, which pairs each element with all
subsequent elements of the word array and prevents the addition of unnecessary pairs. Part (a) earned 5 points.

In part (b) point 6 was earned by correctly accessing all elements using a for loop and the get method on
allPairs. Point 7 was earned by correctly calling the methods getFirst and getSecond on elements of
allPairs. The response compares the first and second components of a pair in the list using the equals
method, which earned point 8. Point 9 was earned by correctly initializing a count variable and incrementing it
only when a match is found. 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 2 (continued)

Sample: 2B
Score: 6

In part (a) the response creates a new ArrayList as a local variable and copies all elements to allPairs.
Because the instance variable allPairs is never instantiated, the response did not earn point 1. Point 2 was
earned by accessing all elements of the words array in the nested for loops. Although the response
constructs a WordPair object, point 3 was not earned because the second parameter is an index instead of an
element of words. Point 4 was earned by correctly adding all necessary pairs to allPairs. Within the nested
loops, the inner loop control variable is initialized to 1, which pairs each element with all elements except the first
element of the word array. Because of this, the response adds unnecessary pairs in which the first component of
the pair occurs after the second component in the array of words, and it did not earn point 5. Part (a) earned
2 points.

In part (b) point 6 was earned by correctly accessing all elements using a for loop and the get method on
allPairs. Point 7 was earned by correctly calling the methods getFirst and getSecond on elements of
allPairs. The response compares the first and second components of a pair in the list using the equals
method, which earned point 8. Point 9 was earned by correctly initializing a count variable and incrementing it
only when a match is found. Even though the response does not close the brace of the for loop, the indentation
demonstrates that the return statement is located outside the loop. Part (b) earned 4 points.

Sample: 2C
Score: 2

In part (a) the response did not earn point 1 because it does not create and assign a new ArrayList to
allPairs. Point 2 was not earned because the response does not access any elements of the array words.
Incorrect use of the size method to obtain the length of the array did not affect the response’s score. Because
the construction of the WordPair object is missing the keyword new and the parameters are indexes instead
of elements of words, point 3 was not earned. Similarly, point 4 was not earned because the response adds
pairs of indexes to the list instead of adding pairs of elements of the word array. Point 5 was earned by initializing
the inner loop control variable to be one greater than the outer loop control variable, ensuring that no
unnecessary pairs are added to the list. Part (a) earned 1 point.

In part (b) point 6 was earned by correctly accessing all elements using a for loop and the get method on
allPairs. Because the response does not call the getFirst or getSecond methods, point 7 was not
earned. Point 8 was not earned because the response compares WordPair objects instead of components of the
word pair. Point 9 was not earned because the condition that guards the accumulator compares different pairs
instead of portions of the same pair; therefore, pair-like values are not being counted. Part (b) earned 1 point.

© 2018 The College Board.


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

You might also like