AP
® COMPUTER SCIENCE A
2014
GENERAL 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.
1-Point
Pena
l
ty
(w)
E
xtraneous
code
that
causes
side
effect
(e
.g.,
writing
to
output,
failure
to compile)
(x)
Local variables
used
but
none declared
(y)
D
estruction
of
persistent
data
(e
.g
.,
changing
value
referenced
by
parameter)
(z)
Void
method
or constructor
that
returns a value
No
Penalty
o
E
xtraneous
code
with
no
side
effect
(e
.g.,
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
(x
~
~
<>
*)
o
[]
()
<>
vs. vs.
o =
instead
of
==
and
vice
versa
o
Array/collection
access
confusion
[
] get
o
length/size
confusion
for
array,
String
List
,
or
ArrayList
,
with
or
without
( )
o
E
xtraneous
[]
when
referencing entire array
o
[i,j]
instead
of
[
i][j]
o
E
xtraneous
size
in
array declaration,
int[size
]
nums = new int[size];
e.g
.,
o
Missing
;
provided majority
are
present
and
indentation
clearly conveys
intent
o
Missing
{ }
where
indentation
clearly conveys
intent
and
{ }
are
used
elsewhere
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
un
a
mb
i
guously
inferred
from
context;
for
example,
"
A
rayList
"
instead
of
"
A
rrayList
".
As
a counterexample,
note
that
if
the
code declares
"
B
ug bug;
",
then
uses
"
B
ug.move()
"
instead
of
"
b
ug.move()
",
the
context
does
not
allow
for
the
reader
to assume the
object
instead
of
the
class.
© 2014
The
College Board.
Visit
the
College Board
on
the
Web: www.collegeboard.org.
AP®
COMPUTER SCIENCE A
2014
SCORING GUIDELINES
Question
3:
Seating
Chart
Part (a)
S
e
a
t
i
n
gChart
constructor
5
points
Intent:
Create
SeatingChart
object
from
list
of
students
+1
s
eats = new Student[rows][cols];
(or equivalent code)
+1
Acc
esses
all
elements
of
studentList
(no
bounds
errors
on
studentList
+1
Acc
esses
all
necessary
elements of
seats
array
(no
bounds
errors
on
seats array,
point
lost
if
access
not
column
-major
order)
+1
Assigns
value from
studentList
to
at
least
one
element
in
seats
array
+1
On exit:
All
el
ements
of
seats
have
correct valu
es
(minor
loop
bounds
errors ok)
Part (b)
removeAbsentStudents
5
points
!
!
Intent:
R
emove
students
with
more
than
given
number
of
absences
from
seating
chart
and
return
count
of
students
removed
+1
Accesses
all
elem
ents
of
seats
(no
bounds
errors)
+1
Calls
getAbsenceCount()
on
Student
object
(point
lost
if
null
case
not
handled
correctly)
+1
Assigns
null
to all el
ements
in
seats
array
when
absence
count
for occupying
student>
allowedAbsences
(point
lost
if
seats
array
element
changed
in
other
cases)
+
1
Computes
and
returns correct
number
of
students
removed
I
Question-Specific
Penalties
-2
(v)
Consistently
us
es
incorrect array
name
instead
of
s
eats
or
s
tudentList
© 2014
The
College Board.
Visit
the
College Board
on
the
Web: www.collegeboard.org.
AP®
COMPUTER SCIENCE A
2014
CANONICAL SOLUTIONS
Question
3:
SeatingChart
Part
(a):
p
ublic SeatingChart(List<Student> studentList, int rows, int cols){
seats=new Student[rows][cols];
int studentIndex=0;
for (int col = 0; col < cols; col++){
for (int row = 0; row < rows; row++){
if (studentIndex < studentList.size()){
seats[row][col] = studentList.get(studentIndex);
studentIndex++;
}
}
}
}
Part
(a)
alternate:
p
u
bli
c SeatingChart(List<Student> studentList, int rows, int cols){
seats=new Student[rows][cols];
int row=0;
int col=0;
for (Student student : studentList){
seats[row][col]=student;
row++;
if (row==rows){
row=0;
col++;
}
}
}
Part
(b):
p
u
bli
c int removeAbsentStudents(int allowedAbsences){
int count = 0;
for (int row=0; row < seats.length; row++){
for (int col=0; col < seats[0].length; col++){
if (seats[row][col] != null &&
seats[row][col].getAbsenceCount() > allowedAbsences){
seats[row][col]=null;
count++;
}
}
}
return count;
}
The
se
c a
nonic
al
so
lutions
serve
an
expository
ro
le,
dep
i
cting
genera
l a
pproaches
to
so
lution. E
ac
h reflects
on
ly
one
i
nstance
from
the
infinite
se
t
of
va
li
d
so
luti
ons
.
The
so
luti
ons
are
pr
ese
n
ted
in a
codmg
style
chosen
to
enha
nc
e
rea
d
abi
lit
y
and
facili
tate
und
ers
tan
d ing.
© 2014
The
College Board.
Visit
the
College Board
on
the
Web
www
.coll
eg
eboar
d .o
rg
.
©2014 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
Complete the
Sea
tingChart
constructor below.
I*
* Creates a seating chart with the given number of rows and columns from the students in
*
studentList.
Empty seats in the seating chart are represented by
null.
*
@par
am
rows
the number of rows of seats
in
the classroom
*
@par
am
cols
the number
of
columns
of
seats
in
the classroom
* Precondition:
rows
>
0;
cols
>
0;
*
rows
*cols>=
studentList.size()
* Postcond,ition:
* - Students appear
in
the seating chart in the same order
as
they appear
*
in
studentList,
starting at
seats
[OJ
(OJ.
* -
seats
is filled column
by
column from
studentList,
followed by
any
* empty seats (represented by
null).
* -
studentList
is unchanged.
*I
public
SeatingChart(List<Student>
studfil}tList,
int
rows,
int
cols)"\_
seo_ts
-=.
~
,S-u,d.rar,t C
('OWS
J t
co~s
J
~
1\~~;
j-=.
o ; j <cols> j +-l-
)-\_
for
(int
i:::
a ', I <. r~w s l \ -+-\) {
J
Unauthorized copying o,- n,use
of
any part
of
this
page la Illegal.
}
;4'
Cs\ <= s-l.vde.n~Li.s t .
.s,~)
{
se.o:ls C i }
Cj
l=-
owd<21'tli
cil
-3et
( s I ) ;
.s I
-t4
,
)
}
GO
ON TO THE NEXT PAGE.
-
12-
©2014 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
3Ab
Complete method
removeAbsentStudents
below. ·
I * * Removes students who have more than a given number of absences from the
* seating chart, replacing those entries in the seating chart with
nul
1
* and returns the number
of
students removed.
*
@param
allowed.Absences
an
integer>= 0
*
@return
number
of
students removed from
seats
* Postcondition:
* -
All
students with
allowed.Absences
or fewer
are
in their original po~tions
in
seats.
* - No student in
seats
has more than
allowed.Absences
absences.
* - Entries without students
co
ntain
null.
*I
public
int
removeAbsentStudents(int
allowed.Absences>.-{
int
~~~=0~
·
for ( i
rrl
,
-:::
C -, i <
~.
l~
~
;-
i
+--t-
) {
fa\-
(if'\t
j
==o~
_J~
<
~[O]
l
e.Y\,:Jth
~j+-t )\_
·,f
(Se:xts
l I J
CJJ
)
=-
1"'\ul
I
)-t
.
·,-r
(~C
i
1Cj
J_3~h-ll))al~
.
Srots
(1]~
1
~
f'\V.J\
~
UXA
t"\-1;,,
-t
;
}
}
J
}
'('e.,."t.J,Al"I"\
CPv.r-.-l ,
}
//
if
thi~
is
-l:,h~
fis.l
bme
~b~,eryl.Stucbri~S
;s
tf'\'-0~
1
If
Che,
c0v-lcl
lten::rt~
i:hrt>~9
h
-lhe.
o..rrO.j
G\S
vR-- cld
1()
q,t,eSt10"
//
o. ot'\d
br-eo.k
th~h
-t5e-
loop
tl--e
,ns.w.rte-
We-
.fuc.trd
C\ n~ll,
//
WD~bl
k,
.
tv'O
r
e.,
f'CAt\
-l:c
""e
e.f.f'.'6e,n{
bc...-t.
woe,,.(d.1/\'{
\M)t"
~
-f'o~
I I
ro
u
H.i
pe-
i n
vc,
k,
2-:)
Unauthorized copying or reuse
of
any part ol this page Is Illegal.
GO
ON TO THE NEXT PAGE.
-15-
©2014 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
Complete the
SeatingChart
constructor below.
I ** Creates a seating chart with the given number
of
rows and columns from the students
in
*
studentList.
Empty seats
in
the seating chart are represented
by
null.
* @param
rows
the number of rows
of
seats in the classroom
* @param
cols
th
e number of columns of seats in the classroom
* Precondition:
rows
>
0;
cols
>
0;
*
rows*
cols>=
studentList.size()
* Postcondition:
*
*
*
*
*
* /
- Students appear in the seating chart
in
the same order as they appear
in
studentList,
starting
at
seats[O]
(OJ.
-
seats
is filled column by column
£rom
studen
tList,
followed by any
empty seats (represented by
null).
-
studentList
is unchanged.
public
SeatingChart(
Li
st<Student>
int
rows,
int
studentList,
cols)
l
\Y\~
fO)-::.
0)
. . .
> W,-\-)
;:;.
y'\J.J..}J
I
i'\-\-
t-f
~-.,,.il:'
"J
~.o
\
':i
'1;
ff'(
ir.+ .
f.:=
CJj
r L
r-ew.i
_)
r+i--) f
to-r
(.
(Y\-\-
l
~
~,
l
<-
cots)
l.?r~)
[
Unau1horlzed copying
or
reuse
of
any
part
of
this
page
Is
Illegal.
~Ct.--\~
T t J ( ·( j
=-
$~.Jc,\c~\-tL;
~;-
j--lr(
po
))
J
GO
ON
TO
THE
NEXT
PAGE
.
-12-
©2014 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
Complete method
removeAbsentStudents
below.
I**
Removes students who have more than a given number
of
absences from the
* seating chart, replacing those entries in the seating chart with
nul
1
* and returns the number of students removed.
* @par am
allowed.Absences
an intege
r>=
0
*
@return
number of students removed from
seats
*
Po
stconditi9n:
* - All studenrs with
allowedAbsences
or fewer are in their original posip.ons in
seats.
* -
No
student in
seats
has more
than
allowedAbsences
absences.
* - Entries without students contain
nul
1.
*/
public
int
removeAbsentStudents(int
allowed.Absences))
t
I\~
'TO
\-o.-\
-:.
0
)
l
6
or(_l'fYr
(--
~'
{'
( Jl<,\.~~'
~
't.-h-~,Vn / r\.\-)
,i~-r
{_
0'\
t- l :
~)
L
c..
...S-lt-..:\
s Le'":\.
lo~
-0,,
~
l
++--:)
Unauthorlz-ed copying
or
reuse
of
any
part
of
this page
Is
Illegal.
i
.f:
( ~
,\-
1
t
l~
')
C
(.,
') I J
"&1-AJ,
~~2
~.
tC.)
>
oJ
I
0~
tt!
.
~\
~~)
l
Ju,-,),.
~
t r
'"l
t.
c.)
-::::
vw'd
.
./
10hi~\
t-\--_)
GO
bN
TO THE NEXT PAGE.
-15-
©2014 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
Complete the
SeatingChart
constructor below. ·
I**
Creates a seating chart with the given number
of
rows and columns from the
studentS
in
*
studentList.
Empty seats
in
the seating chart are represented by
null.
*
@par
am
rows
the number
of
rows of seats in the classroom
* @param
cols
the number
of
columns
of
seats in the classroom
* Precondition:
rows
>
0;
cols
>
0;
*
rows*
cols>=
studentList.size()
* Postcondition:
* - Students appear in the seating chart
in
the same order
as
they appear
* in
studentList,
~tarting at
seats
(OJ
[OJ.
* -
seats
is filled column
by
column from
studentList,
followed by any
* empty seats (Iepresented by
null).
* -
studentList
is
W?changed.
*I
public
SeatingChart(List<Student>
studentList,
int
rows,
int
cols)
- ,
)
1
""'"
~l\6
~"'
::
0;
fc.- c
\""1-
'i.-=-·o,·
x <
row"
; x.t-t-
"')
'i
f.:.r-(
""-t-·,r~o,·
1
L (o\c; i
'(!-+
)\
NOi"
Unauthorized copying
or
reuse
of
any
part
of
this page
la
Tilegal.
t~ ( I ~+od~~l.~~~. Qt;.l/11~f'II)
::::::
t1v\\
)t
//
;F
o.)1-oF-
(
~~•J
[x J
[-y
J
:::
s\.vi<I'\~ Li L 9t~ (
tr-,J.
e)lc) '
l
I '
e~ei~·
1
..s
to.1-s
Cx
1 C
'-/1
::
"'"''
\/
GO ON
TO
THE
NEXT PAGE.
-12-
©2014 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
Complete method
removeAbsentStudents
below.
/
**
*
*
*
*
*
*
*
*
* /
Removes students who have
more
than a given number
of
absences from the
seating
chart, replacing those entries in the seating chart with
nul
1
and returns
the
number
of
students removed.
@param
allowed.Absences
an
integer>=
0
@return
number
of
students removed from
seats
Pos
t
co
n
dition:
- All srudents with
allowed.Absences
or fewer are in their original positions
in
seats.
-
No
student in
seats
has more than
allowed.Absences
absences.
-
Entries
without students contain
null.
public
int
removeAbsentStudents
.
(int
allowed.Absences)
~'"'L
c.+
:::.
Q;
f0r-
( ,'
t"\
+-
,.-
-:
0 :
><
...::.
n:,.....,c; i x+-+
)i
.
.f.:rl
,'
1'1\.,.-y
"0,
· y
'--
(.0\\,' y++) f
i F . c
it",~\~
!ii-.:J
t
~?
;
'3
~~
~
A
~st"<
tCo
,_),..
{).,
~n
~('
J,fH,t
<"
«s)
~
.S(c.\\.-.s
(1tJ(
:y
J .
::
(),>I\/
) ,
<.
t,-4-+,-
...
-
J,'
Unauthorized copying or
rouse
or
any port o1
this
page
is illegal
1
J
~
I
.........
,
GO
ON
TO T
HE
NE
XT PA
GE.
-1
5-
AP
®
COMPUTER SCIENCE A
2014 QUESTION OVERVIEWS
Question 3
Overview
T
his question involved the construction, initialization, and manipulation of a two-dimensional array. It also
tests the student’s ability to traverse a List, manage a counter, and return a value from a method.
Students were asked to implement a constructor and a method of the class. SeatingChart
In part (a) students were asked to implement a constructor, which required the instantiation of the
i
nstance variable seats, a 2D array of Student objects, whose dimensions were determined by the
parameters rows and cols. The elements of studentList were to be mapped to the 2D array
seats in column-major order until all list elements had been assigned to the 2D array. Any remaining
elements of the 2D array held their default null values.
In part (b) students were required to examine the instance 2D array seats
, removing all Student
elements whose absence count exceeded the parameter allowedAbsences by replacing the
Student object with null. The method calculated and returned the number of Student objects that
were removed.
Sample: 3
A
Score: 8
In part (a) the student correctly creates the seats array as a two-dimensional array of Student
objects. The student uses nested for loops to access all of the elements of seats in column-major
order and attempts to fill the seats array with elements from the studentList, earning the “accesses
all necessary elements of seats array” and “assigns value from studentList to at least one element in
seats arraypoints. The student did not earn the second point because the condition
s1 <= studentList.size() incorrectly checks the index of the studentList. This causes an
exception to occur. At the time the exception occurs, all elements of studentList have been correctly
mapped to the seats array in column-major order, so the student earned the “all elements of seats
have correct valuespoint. The student earned 4 points in part (a).
In part (b), the student accesses all of the elements
of the seats array. Each element is checked to
ensure it is not null before calling its getAbsenceCount() method. Whenever a student’s absence
count exceeds allowedAbsence, the Student object is removed from the seats array by replacing
it with null. A counter is correctly declared, initialized, updated, and returned to report the number of
students removed from the seats array. The student earned 4 points in part (b).
Sample: 3
B
Score: 4
In part (a) the student creates the seats ar
ray as a two-dimensional array of integers instead of
Student objects, so the students does not earn the “seats = new Student[rows][cols]point.
The student correctly accesses all elements from the studentList, breaking the nested loops when the
end of the list is reached. However, checking the index after using it fails whenever
studentList.size() == 0, so the student does not earn the “accesses all elements of
studentListpoint. The student attempts to use nested for loops to access all of the elements of
seats in column-major order, but reverses the row and column indexes when accessing elements from
© 2014 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
AP
®
COMPUTER SCIENCE A
2014 QUESTION OVERVIEWS
Question 3 (continued)
the array. As a consequence, the response does not earn the “accesses all necessary elements of seats
arraypoint and an exception occurs. Since at least one element of studentList is assigned to the
seats array, the student earned the “assigns value from studentList to at least one element in seats
arraypoint. At the time the exception occurs, not all elements of studentList have been correctly
mapped to the seats array in column-major order, so the student did not earn the “all elements of
seats have correct values” point. The student earned 1 point in part (a).
In part (b), the student accesses all of the elements of the seats ar
ray, earning the seats = new
Student[rows][cols]point. The student did not earn the “accesses all elements of studentList
point because each element is not checked to ensure it is not null before calling its
getAbsenceCount() method. In all other cases, whenever a student’s absence count exceeds
allowedAbsence, the Student object is removed from the seats array by assigning null to its
row and column position. A counter is correctly declared, initialized, updated, and returned to report the
number of students removed from the seats array. The student earned 3 points in part (b).
Sample: 3
C
Score: 3
In part (a) the student does not create the seats ar
ray, and did not earn theseats = new
Student[rows][cols]point. The student attempts to access all elements from the studentList,
but has a bad out-of-bounds check and fails to increment the index. As a result, the student did not earn
the “accesses all elements of studentListpoint. The student attempts to use nested for loops to fill
the seats array with elements from the studentList. The seats array is filled in row-major order
instead of column-major order, thus the response did not earn the “accesses all necessary elements of seats
arraypoint. Since at least one element of studentList is assigned to the seats array, the student
earned the fourth point. The student did not earn the “all elements of seats have correct valuespoint
because the seats array was not filled in column-major order and the value studentList.get(0)has
been assigned to each element of the seats array due to the studentList index not being
incremented. The student earned 1 point in part (a).
In part (b), the student attempts to access all of the elements of the seats array. Since the rows and
cols var
iables are not defined for this method, the response does not earn the “accesses all elements of
seats” point. The student did not earn the Calls getAbsenceCount() on Student object” point
because each element is not checked to ensure it is not null before calling its getAbsenceCount()
method. In all other cases, whenever a student’s absence count exceeds allowedAbsence, the
Student object is removed from the seats array by assigning null to its row and column position.
A counter is correctly declared, initialized, updated, and returned to report the number of students
removed from the seats array. The student earned 2 points in part (b).
© 2014 The College Board.
Visit the College Board on the Web: www.collegeboard.org.