Ap23 Apc Computer Science A q3
Ap23 Apc Computer Science A q3
AP Computer Science A
®
Inside:
Free-Response Question 3
R Scoring Guidelines
R Student Samples
R Scoring Commentary
© 2023 College Board. College Board, Advanced Placement, AP, AP Central, and the acorn logo are registered
trademarks of College Board. Visit College Board on the web: collegeboard.org.
AP Central is the official online home for the AP Program: apcentral.collegeboard.org.
AP® Computer Science A 2023 Scoring Guidelines
Apply the question scoring criteria 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
• Extraneous code with no side-effect (e.g., valid precondition check, no-op)
• Spelling/case discrepancies where there is no ambiguity*
• Local variable not declared provided other variables are declared in some part
• private or public qualifier on a local variable
• Missing public qualifier on class or constructor header
• Keyword used as an identifier
• Common mathematical symbols used for operators (× • ÷ ≤ ≥ <> ≠)
• [] vs. () vs. <>
• = instead of == and vice versa
• length/size confusion for array, String, List, or ArrayList; with or without ( )
• Extraneous [] when referencing entire array
• [i,j] instead of [i][j]
• Extraneous size in array declaration, e.g., int[size] nums = new int[size];
• Missing ; where structure clearly conveys intent
• Missing { } where indentation clearly conveys intent
• Missing ( ) on parameter-less method or constructor invocations
• 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.
Canonical solution
(a) cleanData
(b) longestHeatWave
--
·· Quedon
• Important: Completely flu 1l the c1rcii, · " QUNtlon 1 Question 2 ' � t 4
� ., ' .
--
that con,sponds to the question you
are answering on this page, 0 0 0
-�-· ..
Begin your resporiH to each question at the top of a new page.
--
• . ' '. . ) , .. l
..--
I - - i
3
J
3 --
--
--
--
--
--
--
--
--
--
-
-- •■t.
--
--
11111!!'
--
--
--
Pagel ...
-- .
--
.
only:bo'tifrr'wt"- :you; it.me.
UN a pdll 6 outside� Do NOt
■ ■ ■ ■ •• •• ••
• • •• ••
0056149
•� •• •-
Q3 Sample A 2 of 2
-- ·-·-· --� �. ··----·------·-- ----·--•-·-·-----·----
• �
--
that col'T88P()nds to tne question you
areanewertngonthla�. 0 0 0
--
irJ Covr'lt-:: Dj rl)'t ttt111-p-:::. Oj
b-,<- Li"+ ,-�, , c.. �f..e.r°'+vr,zs-_ l��+1' / +�) f
-- / � \--\-.r�<:."r\o)J)�
--
(��O\+vr��.°:).e�(i\
:¼mp.
-
1
7 l;
-- \.J \,· I� ( t<"" �<;; .\vr.e5. OJ e � c.-\ ) l, }._ ( �rh Jf) '-.
te...,...,p +-.f j
---
'5
1
-- i+ ( ( O..J"f Lf eV'lle) S.
---
c..ovt1t-:: tem'f' i
3
--
--
--
--
--
--
--
--
-- \
--
- -
---
--
--
--
--
--
-• • •• •• •• �•
Q3 Sample B 1 of 2
·--·---�---- �-
-_-.. 7
4 .. t 1·
·-----·---
--
are answerln'g on this page, 0 0 •
' - r-- �� .....
Begin your response to each question at the top of a new page.
© --
--
-pi1l,/1 c., vtJ ,-r, c)� °!)-4t;i. C-,o,,,hli l0u1� / 1;i0uk/i, u7'� )f..
---
1
---
lr(-r-E-M'),t17A'tv'ftt:-S. e,e:f(i) L lcw6"ll f lt-e ,-q;,67fA7vU5, 6P'{;)� v�)[ : :
--
--
3
f
j
- '
--
, •• 4
\
'
-- ..
--
--
--
--
,,
--
-
--
--
---
--
--
--
---
·- --
Yodf rilM.:bdNOT �-� ttlebo'i
• ...
&J.. .�� only. o&'NCW1wrtt.
d
■
••
.0046022 •• •••• ••
•• •• ••
----- - ·---·--·----
Q3 Sample B 2 of 2
--- O\Mdon 1
---
Important Cpmpletely fill In the circle QUNtlon 2 Queetlon 3 QUNtlon 4 •
that correaponda 1D the queatlon you
are answering on this page. 0 0 e 0
--- G)
Begin your response to each� at the 1Dp CJf a new-page..
i
�
---
1-o,,\rrw;t\)�,s, �;;t(; ..-1) > -th,US kc1 l1>) f
C..0 V .\)t .,- -t j
·--
---
-,_
---
i-
Ir
---
---
---
,_--
--
---
---
---
---
---
--• • •• •• • • •• a...-e
------· ,,,,,, __ ____
, , ·-
Q3 Sample C 1 of 1
---
--
• Important: Completely fill In the dircle Quutlon 1 aue.tlon 2 QUNtlon 3 Question 4
that oorresponds to the question you
0 0 • 0
--
are answering on this page.
Y"'-v:-t" A !
t ---
Begin your mponse to each question at the top of a new page.
f\J.bti e- � o( �CD� l t.Lowi,� lav..e.r, ,&c..,.bl� �)
.flDr- l i\'\..\- i::: D j I I. �,tw-e.�. �· 'H \ t.
\� l�./wi!S. �+(;\ L l��) t --
��s. � l-,), --
---
..--
�
�� i� (�S-}<-+l,\--, l.-lf�) i
--
��. �\"'e..li)
�
--
--
--
-
--
--
--
---
--
--
--
--
·- ·-
U.i'a 9lflCff �-Do Mo1' wrt1a your name. Do' NOT write outaldtt the box.
0051144 ■
••
■■■■■
• • ••
■■
•• • -
AP® Computer Science A 2023 Scoring Commentary
Question 3
Note: Student samples are quoted verbatim and may contain spelling and grammatical errors.
Overview
This question involved the traversal, analysis, and manipulation of an ArrayList object
containing numbers modeling recorded temperatures. Students were expected to write two methods
of the WeatherData class, using its ArrayList instance variable.
In part (a) students were expected to write a loop that accessed each element of the ArrayList
instance variable temperatures and removed any elements that were outside of a range specified
by the parameters upper and lower. Inside the loop, students were expected to use a conditional
to identify elements for removal from the list and to call the remove method on the instance
variable temperatures.
In part (b) students were asked to (1) identify the lengths of any heat waves of consecutive elements
in temperatures that were greater than the parameter threshold, and (2) determine and return
the length of the longest of the identified heat waves.
Sample: 3A
Score: 8
In part (a) point 1 was earned because the response iterates over all elements of the list and correctly
accesses each one. This response uses a for loop to iterate forward through the list, but other
correct approaches exist. Point 2 was earned because the response makes the correct comparisons
between an element of temperatures and the parameters upper and lower. To earn the point,
the response must use the correct comparison operator (e.g., < or >) and the correct logic operator
(e.g., ||). Point 3 was earned because the response correctly calls the remove method to remove
an element from the temperatures list. Point 4 was earned because the algorithm results in the
correct values being removed from temperatures. When a response uses an increasing index in a
for loop, a correct algorithm requires a decrement of the loop control variable after the call to
remove in order to avoid skipping elements.
In part (b) point 5 was earned because the response iterates over all elements of temperatures,
accessing each one properly. This response uses a for loop with an incremented index value, but
other approaches could also be correct. Note that the use of length instead of size in the for
loop is one of the minor errors for which no penalty is assessed on this exam. (See the “No Penalty”
Question 3 (continued)
section on page 1 of the Scoring Guidelines for a complete list.) Point 6 was earned because
elements of the list are appropriately compared to threshold. To earn the point, the response
must use the correct comparison operator. Most correct responses will not require the use of any
logical operators. Point 7 was earned because the variable temp, which measures the length of a
heat wave, is initialized and then incremented in some cases, based on the results of a comparison
involving an element of temperatures. Point 8 was not earned because the loop control variable
i is not updated in the while loop, resulting in an infinite loop. Point 8 assesses the algorithm
implemented to identify a single heat wave. As a result of the infinite loop, the length of a heat wave
is not correctly determined because the end of a heat wave is never identified. Point 9 was earned
because the algorithm compares the identified current heat wave length, temp, to a maximum heat
wave length, count; updates the maximum length when appropriate; and eventually returns the
maximum length. Note that the infinite loop causes point 8 to not be earned and is not assessed as
part of point 9.
Sample: 3B
Score: 4
In part (a) point 1 was earned because the response correctly accesses all elements of
temperatures. Using length instead of size is one of the minor errors for which no penalty is
assessed on this exam. (See the “No Penalty” section on page 1 of the Scoring Guidelines for a
complete list.) Point 2 was earned because the response makes the correct comparisons between an
element of temperatures and the parameters upper and lower. Point 3 was earned because
the response correctly calls the remove method to remove an element from the temperatures
list. The argument to the remove method in this response is the element to be removed, rather than
the index of the element to be removed. This is valid and removes the first instance of that element in
the list. Point 4 was not earned because the algorithm skips over any element immediately following
a removed element. Decrementing the variable i after the call to remove would have avoided this
error.
In part (b) point 5 was not earned because the response attempts to access the list element at index
i + 1, causing an out-of-bounds error at the end of the list. A similar error occurs when the
response attempts to access the list element at index i - 1 at the beginning of the list. Point 6 was
not earned because the list element at index i - 1 is incorrectly compared to threshold. When
multiple comparisons to threshold are made, all must be correct to earn the point. A correct
comparison must either test if the element is strictly greater than threshold or if the element is
less than or equal to threshold. Point 7 was earned because the variable count, which
measures the length of a heat wave, is properly initialized and incremented as a result of a
comparison involving temperatures. Point 8 was not earned because the variable count is
never reset to zero, so the length of a given heat wave is not determined. Furthermore, the response
does not count all temperatures above the threshold due to the additional tests for temperatures at
indices i - 1 and i + 1. Point 9 was not earned because no algorithm to find the length of the
longest heat wave is implemented.
Question 3 (continued)
Sample: 3C
Score: 3
In part (a) point 1 was earned because the response accesses all elements of temperatures. Point
2 was earned because the response makes the correct comparisons between an element of
temperatures and the parameters upper and lower. Point 3 was earned because the response
correctly calls the remove method to remove an element from the temperatures list. Point 4
was not earned for either of the following reasons. First, the algorithm skips over any element
immediately following a removed element. Decrementing the variable i after the call to remove
would have avoided this error. Second, the response returns the instance variable temperatures
from within the void method. Returning or printing the list makes the algorithm incorrect and is
assessed in this point. Note that there is a related penalty in the “1-Point Penalty” list, but that
penalty is not applied because the error is assessed as part of the algorithm within this rubric point.
In part (b) point 5 was not earned because the response attempts to access the element at index
i + 1, causing an out-of-bounds error at the end of the list. Point 6 was not earned because the
boolean expression is invalid; there is no comparison involving the first get operation. When
multiple comparisons to threshold are made, all must be correct in order to earn the point. Point
7 was not earned because no variable measuring the length of a heat wave is ever incremented. Point
8 was not earned because no variable measuring the length of a heat wave is ever reset at the end of
an identified heat wave. The response finds the difference between consecutive temperature values
rather than incrementing a count, and therefore, it has not determined the length of at least one heat
wave. Point 9 was not earned because no variable is updated when a longer heat wave is identified.
Furthermore, the return statements in both the if and else blocks result in an early return in
the first iteration of the loop.