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

Ap18 Computer Science A q4

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

Ap18 Computer Science A q4

Copyright
© © All Rights Reserved
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 4


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 4: Latin Squares

Part (a) getColumn 4 points

Intent: Create a 1-D array that contains the values from one column of a 2-D array
+1 Constructs a new int array of size arr2D.length

+1 Accesses all items in one column of arr2D (no bounds errors)

+1 Assigns one element from arr2D to the corresponding element in the new array

+1 On exit: The new array has all the elements from the specified column in arr2D in the correct order

Part (b) isLatin 5 points

Intent: Check conditions to determine if a square 2-D array is a Latin square


+1 Calls containsDuplicates referencing a row or column of square

+1 Calls hasAllValues referencing two different rows, two different columns, or one row and one
column

+1 Applies hasAllValues to all rows or all columns (no bounds errors)

+1 Calls getColumn to obtain a valid column from square

+1 Returns true if all three Latin square conditions are satisfied, false otherwise

Question-Specific Penalties

-1 (r) incorrect construction of a copy of a row

-1 (s) syntactically incorrect method call to any of getColumn(), containsDuplicates(), or


hasAllValues()

© 2018 The College Board.


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

Question 4: Scoring Notes

Part (a) getColumn 4 points


Points Rubric Criteria Responses earn the point if Responses will not earn the point if
they... they...
Constructs a new int • only create an ArrayList
+1 array of size
arr2D.length
Accesses all items in one • declare the new array of an • switch row and column indices
column of arr2D (no incorrect size and use that
+1
bounds errors) size as the number of loop
iterations
Assigns one element from • use ArrayList methods to add
arr2D to the to array
+1
corresponding element in
the new array
On exit: The new array • switch row and column indices
has all the elements from • do not use an index when
+1
the specified column in assigning values to the array
arr2D in the correct order
Part (b) isLatin 5 points
Points Rubric Criteria Responses earn the point if Responses will not earn the point if
they... they...
Calls • reference any row or
containsDuplicates column of square, even
+1 referencing a row or if the syntax of the
column of square reference is incorrect
Calls hasAllValues • reference any two distinct
referencing two different rows, two distinct
rows, two different columns, or a row and
+1
columns, or one row and column of square, even
one column if the syntax of the
reference is incorrect
Applies hasAllValues • only reference one array in the
+1 to all rows or all columns call to hasAllValues
(no bounds errors)
Calls getColumn to • reverse parameters
+1 obtain a valid column from
square
Returns true if all three • test the three sets of
Latin square conditions conditions and return the
+1
are satisfied, false correct value
otherwise

Return is not assessed in Part (a).

© 2018 The College Board.


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

Question 4: Latin Squares

Part (a)

public static int[] getColumn(int[][] arr2D, int c)


{
int[] result = new int[arr2D.length];

for (int r = 0; r < arr2D.length; r++)


{
result[r] = arr2D[r][c];
}
return result;
}

Part (b)

public static boolean isLatin(int[][] square)


{
if (containsDuplicates(square[0]))
{
return false;
}

for (int r = 1; r < square.length; r++)


{
if (!hasAllValues(square[0], square[r]))
{
return false;
}
}

for (int c = 0; c < square[0].length; c++)


{
if (!hasAllValues(square[0], getColumn(square, c)))
{
return false;
}
}

return true;
}

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 method getColumn below.

/** Returns an array containing the elements of column c of arr2D in the same order as they
* appear in arr2D.
* Precondition: c is a valid column index in arr2D.
* Postcondition: -arr2D is unchanged.
*/
public static int[] getColumn(int [] [] arr2D, int c)

{ , �-\· [ QvV V 2..0 , �


-H,-.]
; ..,.-1 (1 0 (,(,-\ p V'; -I = i-u.w.
i -f-1·)
iO. l,c.�-4-\h )
.fo� (irvl ·,-;: 0) i '- Q..1/v

f. ovv-tr0---\ L;J:: �.2-P[iJ


le]:;

ve(t,V'v- ov----tp '-' d;

Part (b) begins on page 20

Unauthorlzod copying or reuse of


any part of tills page is Illegal.
GO ON TO THE NEXT PAGE.
-19-

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
Complete method isLatin below. Assume that g_etColumn works as specified, regardless of what / {
you wrote in part (a). You must use getColumn, hasAllValues, and containsDuplicat�s
Ab
appropriately to receive full credit.

/** Returns true if square is a Latin square as described in part (b);


* false otherwise.
* Precondition: square has an equal number of rows and .columns.
* square has at least one row.
*I
public static 'boolean isLatin (int[] [) square)

{
.f'or (i I"-\- i -= 0 .>

Unauthorl:ed copying or reuse of


any part of thl• page ls Illegal.
GO ON TO THE NEXT PAGE.
-21-

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
Complete method getColumn below.

/ * * Returns an array containing the elements of column c of arr2D in the same order as they
* appear in arr2D.
* Precondition: c is a valid column index in arr2D.
* Postcondition: arr2D is unchanged.
*/
public static int[) getColumn (int[) [) arr2D, int c)

·t

Part (b) begins on page 20

Unauthorized copying or reuse of


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

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
Complete method isLatin below. Assume that getColumn works as specified, regardless of what
you wrote in part (a). You must use getColumn, hasAllValues, and containsDuplicates
appropriately to receive full credit.

I** Returns true if square is a Latin square as described in part (b);


* false otheiwise.
* Precondition: . square has an equal number of rows•and columns.
* square has at least one row.
*/
public static boolean isLatin (int[) n square)

l .i� ( 0q00re fol� (( (Hoirl') ):J1J\A1Ccd(') :: �• I

+"rvl i
\

'.[.b; LtV'\ + i ::. I 'i i C. 5 Cf U w(, lQf1 J { h � i 1 ·t)


� if l r\°'-':) A\\ Vo..\v{)):::( �rJCX,✓l ( 01 /
: .{?(A.\5t)
SC{vO-,(l C r1
s •
)
' •
r e, t v r n -0oJ-&-e I

f.o, l'1 ·(\-r t.::. D', t c.. Scioove[o~J ? ( -<r,��\1 /II it··I • \.

\ � ( h ()_.S A I\ \/ o. \ v�s l J 1 vo✓ e [ 0c.)} ,l · _· ::: .fu\Se)
�t; Coll.l""'" (0qowe,
< ';
rLtvrn :f?o..\)e

Unauthorized copying or reuse of


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

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
Complete method getColtimn below.

/** Returns an array containing the elements of column c of arr2D in the same order as they
* appear in arr2D.
* Precondition: c is a valid column index in arr2D.
* Postcondition: arr2D is unchanged.
*I
public static int[) getColumn(int[] [) arr2D, int c)

au Nev�-:: /)eW Arrtvyli1{[ o.rr21'>.l0-15{�.!e(\thJj

{'9r C. -i, =o ;_ ;_ < cuor . le,th I i ti) 1


· o.rr Niw [ �] ::;: o.cr1D C 1- )[c J;

)
retwl\ o.rr New­ ,


Jr
I

Part (b) begins on page 20

Unauthorized copying or rouso of


any part of this page is Illegal.
GO ON TO THE NEXT PAGE.
-19-

© 2018 The College Board.


Visit the College Board on the Web: www.collegeboard.org.
Complete method isLatin below. Assume that get Column works as specified, regardless of what
you wrote in part (a). Yot must use get Column, hasAllValues, and containsDuplicates
I-\ C.,b
appropriately to receive full credit.

' / * * Returns true if square is a Latin square as described in part (b);


* false otherwise.
* Precondition: square has an equal number of rowf, and columns.
* square has at least one row.
*I
public static boolean isLatin (int[] (] square)

· i�{[J O.(r ( = 9(VOce,[o])

-fc'.)( ( i-;_Di � � 5t{UffiC ,fit1f,A; L·H) i


1°�t[] C((r /. :; >f1 l ,;, Jj
t'A({_

; .f C ha A 11 V � lC{e � f
)

-f0c lj :. o I j c_ s111 ",.,,, . le./h . l�,1Jth ) J {' -"{': ( ·


{r'\(CJ c,.aj.=c f/fv� lh'J L1�-c[s1,1•1(- t J;
1r 4
I
I
..f0r ( p : �- z C {l/vn., (1?1/f.. : i, f) f
o.n'J. o.J.d ( 51"c.,c C j J c:? J);

---
')
�(() :: o-(r 2.;

l.f c kA > i-W v,JL\e. �) \


reit.(11 T<ue.. I·

)

(&tiff\ {a {se,)
Unauthorized copying or reu,e of
any part of thl• page Is Illegal.
GO ON TO THE NEXT PAGE.
-21-

© 2018 The College Board.


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

Question 4

Overview

This question tested the student’s ability to:

• Write program code to create, traverse, and manipulate elements in 1D array or ArrayList objects;
• Write program code to create, traverse, and manipulate elements in 2D array objects; and
• Write program code to create objects of a class and call methods.

The students were expected to write two static methods of an enclosing ArrayTester class. Additionally,
students were required to use method getColumn from part (a) and two already-implemented methods of the
ArrayTester class, containsDuplicates and hasAllValues, in their part (b) solutions.

In part (a) students were asked to construct a one-dimensional array and copy the items from a specified column
of a given two-dimensional array into the new array. Students were expected to be able to construct an array with
the correct number of elements, which is the number of rows in the two-dimensional array, not the number of
columns. Once the array was constructed, students were expected to write a loop that accesses each item in the
given column and assigns it to the corresponding element of the new array.

In part (b) students were given a square two-dimensional array and asked to evaluate if the two-dimensional
array was a Latin square. A two-dimensional array of integers is a Latin square if:

• The first row has no duplicates;


• All values in the first row of the square appear in every row of the square; and
• All values in the first row of the square appear in every column of the square.

Sample: 4A
Score: 9

In part (a) an int array of size arr2D.length is correctly constructed. The response earned point 1. A loop
that executes the correct number of times is used to access all items in one column of arr2D, which earned
point 2. All items in a column of arr2D are assigned to the corresponding elements of the constructed array,
which earned point 3. At the end of the method, the constructed array contains all items from the specified
column in arr2D in the correct order. The response earned point 4. Part (a) earned 4 points.

In part (b) the first row of square is checked for duplicates with a correct call to method
containsDuplicates. The response earned point 5. A correct for loop is used to access all rows and
columns of square. The hasAllValues method determines if every row and column of square contains all
the elements of the first row of square. The response earned point 6 and point 7. A correct call to method
getColumn is used, which earned point 8. All three Latin square conditions are satisfied. The response earned
point 9. Part (b) earned 5 points.

Sample: 4B
Score: 6

In part (a) there is an attempt to construct an int array of size arr2D.length; however, the response
incorrectly uses arr2D[0].length. The response did not earn point 1. A correct for loop is used to access
all items in one column of arr2D, which earned point 2. Items in a column of arr2D are not assigned to the
corresponding elements of the constructed array. The response incorrectly assigns the items to int[i] instead

© 2018 The College Board.


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

Question 4 (continued)

of column[i]. The response did not earn point 3. Going forward, it is assumed that all accessed items are
correctly assigned to the constructed array. At the end of the method, the constructed array contains all items
from the specified column in arr2D in the correct order. The response earned point 4. Part (a) earned 2 points.

In part (b) the first row of square is checked for duplicates with a syntactically incorrect call to the method
containsDuplicates. The response earned point 5; however, a question-specific penalty of 1 point was
assessed for the syntactically incorrect call. Correct for loops are used to access all rows and columns of
square. The hasAllValues method determines if every row and column of square contains all the
elements of the first row of square. The response earned point 6 and point 7. A correct call to method
getColumn is used, which earned point 8. All three Latin square conditions are satisfied. The response earned
point 9. Part (b) earned 4 points.

Sample: 4C
Score: 3

In part (a) the response does not correctly construct an int array of size arr2D.length. The response
constructs the array as an ArrayList[arr2D.length.length]. The response did not earn point 1. Going
forward, it is assumed that the array is properly constructed. A loop that executes the correct number of times is
used to access all items in one column of arr2D, which earned point 2. All items in a column of arr2D are
assigned to the corresponding elements of the constructed array, which earned point 3. At the end of the method,
the constructed array contains all items from the specified column in arr2D in the correct order. The response
earned point 4. Part (a) earned 3 points.

In part (b) there is an invalid call to method containsDuplicates that does not include a parameter. The
response did not earn point 5. There is an invalid call to method hasAllValues that does not include any
parameters, so the question-specific syntax penalty cannot be applied. The response did not earn point 6 and
point 7. There is no call to method getColumn. The response did not earn point 8. Some of the Latin square
conditions are incorrectly tested. The response did not earn point 9. Part (b) earned 0 points.

© 2018 The College Board.


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

You might also like