ap14 computer science a q2 - college board · 2017-04-21 · ap® computer science a 2014 scoring...

8
o o o o private public o public o o o [] () <> o = == o [] get o length/size String List ArrayList ( ) o [] o [i,j] [i][j] o int[size ] nums = new int[size]; o ; o { } { } o ( ) o ( ) if while ArayList ArrayList Bug bug; Bug.move() bug.move()

Upload: others

Post on 26-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ap14 computer science a q2 - College Board · 2017-04-21 · AP® COMPUTER SCIENCE A 2014 SCORING COMMENTARY Question 2 (continued) it starts act, so the solution is not awarded the

o

o

o

o private public

o public

o

o

o [] () <>

o = ==

o [] get

o length/size String List ArrayList ( )

o []

o [i,j] [i][j]

o int[size] nums = new int[size];

o ;

o { } { }

o ( )

o ( ) if while

ArayList ArrayList

Bug bug; Bug.move()

bug.move()

Page 2: ap14 computer science a q2 - College Board · 2017-04-21 · AP® COMPUTER SCIENCE A 2014 SCORING COMMENTARY Question 2 (continued) it starts act, so the solution is not awarded the

Director

Rock

class Director extends Rock

Director(){ }

Color.RED setColor super(Color.RED)

act

act

getGrid

setDirection

Page 3: ap14 computer science a q2 - College Board · 2017-04-21 · AP® COMPUTER SCIENCE A 2014 SCORING COMMENTARY Question 2 (continued) it starts act, so the solution is not awarded the

public class Director extends Rock

{

public Director()

{

super(Color.RED);

}

public void act()

{

if (getColor().equals(Color.GREEN))

{

ArrayList<Actor> neighbors = getGrid().getNeighbors(getLocation());

for (Actor actor : neighbors)

{

actor.setDirection(actor.getDirection() + Location.RIGHT);

}

setColor(Color.RED);

}

else

{

setColor(Color.GREEN);

}

}

}

Page 4: ap14 computer science a q2 - College Board · 2017-04-21 · AP® COMPUTER SCIENCE A 2014 SCORING COMMENTARY Question 2 (continued) it starts act, so the solution is not awarded the

©2014 The College Board.Visit the College Board on the Web: www.collegeboard.org.

Page 5: ap14 computer science a q2 - College Board · 2017-04-21 · AP® COMPUTER SCIENCE A 2014 SCORING COMMENTARY Question 2 (continued) it starts act, so the solution is not awarded the

©2014 The College Board.Visit the College Board on the Web: www.collegeboard.org.

Page 6: ap14 computer science a q2 - College Board · 2017-04-21 · AP® COMPUTER SCIENCE A 2014 SCORING COMMENTARY Question 2 (continued) it starts act, so the solution is not awarded the

©2014 The College Board.Visit the College Board on the Web: www.collegeboard.org.

Page 7: ap14 computer science a q2 - College Board · 2017-04-21 · AP® COMPUTER SCIENCE A 2014 SCORING COMMENTARY Question 2 (continued) it starts act, so the solution is not awarded the

AP® COMPUTER SCIENCE A 2014 SCORING COMMENTARY

Question 2

Overview

This question involved reasoning in the context of the GridWorld case study. The question required the design and declaration of a class including proper keywords, inheritance, constructor, method overriding, and accessing and modifying inherited and nonmember instance variables and using constants. This problem tested students’ knowledge of GridWorld classes/interfaces: Rock, Actor, Location, Grid, and Java classes/interfaces from the AP subset: Object, and List<E>. The question necessitated a class header, a no-argument constructor and overriding the act method. Students were required to create the Director class as a subclass of Rock. The question required a no-argument constructor, which set the color state of a director to be Color.RED. Students had to override the act method of the superclass so the same method signature and return type as the superclass (Rock) were required. The director’s behavior required a check of the color state of the director in order to determine how to change colors. When the director starts to act in the green color state, the director will turn all of its neighbors to the right 90 degrees. The director turns (changes the direction of) all of its neighbors right by accessing the neighbor’s current direction state in order to update and set the new direction state of the neighbor. If the director’s color state is green at the beginning of act, the director changes color to Color.RED and vice versa. Sample: 2A Score: 9 The response begins with a proper class heading for a Director class that inherits from Rock. The heading is correctly followed by the class body, surrounded by braces. The no-argument constructor invokes the super class’s constructor with the correct argument of Color.RED. There is an act method, which overrides the superclass’s act method. There is a check for the director’s current color state of green to guard both the director’s color change and turning neighbors. The director will turn red when the director is green at the start of the act method. When the director is not green at the start of act, the director will turn red. This solution completely guards the neighbor’s turning with a check for green (many students did not account for the director’s color state being colors other than red or green). The neighboring actors are collected into a list by getting the current grid and using it to access the neighbors based on the director’s current location. The solution correctly iterates over the list and sets each neighbor’s direction by adding Location.RIGHT to its current direction. Sample: 2B Score: 7 The response begins with a proper class heading for a Director class that inherits from Rock. The heading is correctly followed by the class body, surrounded by braces. The Director no-argument constructor is properly declared and does not need to explicitly invoke the super class’s constructor. The solution correctly uses the setColor modifier method to alter the color state of the constructed director. The use of the constant Color.RED from the Color class was required for full credit when modifying the director’s color in the constructor. There is an act method, which overrides the inherited act method. The director will not alternate colors and was not awarded the "alternates color" point. The director will always turn the neighbors when

© 2014 The College Board. Visit the College Board on the Web: www.collegeboard.org.

Page 8: ap14 computer science a q2 - College Board · 2017-04-21 · AP® COMPUTER SCIENCE A 2014 SCORING COMMENTARY Question 2 (continued) it starts act, so the solution is not awarded the

AP® COMPUTER SCIENCE A 2014 SCORING COMMENTARY

Question 2 (continued)

it starts act, so the solution is not awarded the "only turn when green" point. The getGrid accessor method is used to get the Grid object of the director. The solution checks to see if the grid is valid by comparing it to null (this code was not required but is correct in the context of the case study). The soltuion creates an ArrayList<Actor> reference and sets it to the list returned by the getActors helper method, which the solution includes as part of the Director class. The getActors helper method returns the list generated by the director’s grid object using the getNeighbors method based on the director’s location. The solution uses a correct for-loop to access all of the elements in the list of neighbors. Each neighboring actor’s direction is correctly modified by setting it to the current direction plus 90. Sample: 2C Score: 3 The response begins with a proper class heading for a Director class that inherits from Rock. The heading is correctly followed by the class body, surrounded by braces. The Director no-argument constructor is properly declared and does not need to explicitly invoke the super class’s constructor. The setColor modifier method alters the color state of the director. The correct color argument Color.RED guarantees an initial color state of red. There is an act method, which overrides the Rock class's act method. There is a check for the director's current color state of green, but the guard does not protect any useful code because the getActors method is not defined for the Director class. The solution does not earn any of the 5 points associated with the implementation of the act method.

© 2014 The College Board. Visit the College Board on the Web: www.collegeboard.org.