• Home   /  
  • Archive by category "1"

Gridworld Case Study Quick Reference Publishing

Note: GridWorld will not be featured on the 2015 and subsequent AP CS Exams.

The Grid interface is an important part of the GridWorld Case Study. This practice test is intended to check your understanding of how to use the Grid interface to accomplish common tasks. You should have a copy of the Quick Reference available as you take this practice test.

Question 1

Consider the following code.

Grid<Actor> myGrid = new BoundedGrid<Actor>(4,5); Location loc = /* construct */; myGrid.isValid(loc);

Which of the following replacements for /* construct */ violate the precondition of isValid?

I new Location(4,5);
II new Location(5,6);
III null

(A) II only
(B) III only
(C) I and II only
(D) I, II, and III
(E) None of these violate the precondition.

Question 2

/** * Returns a list of the Actor objects in g. * Precondition: g != null */ public static ArrayList<Actor> getActors(Grid<Actor> g) { /* implementation */ }

Give code to replace /* implementation */ to make getActors work as intended.

Question 3

Grid<Actor> g = new BoundedGrid<Actor>(4,5); Location loc = /* construct */; ArrayList<Location> locs = g.getValidAdjacentLocations(loc)); Collections.sort(locs); System.out.println(locs);

Collections.sort sorts its explicit parameter in increasing order according to the ordering imposed by the compareTo method of the parameter’s elements. For example, the list of Integer objects [6,1,4,2] would become [1,2,4,6]. When an ArrayList is printed, the result of running the toString method on each element is printed.

Give the output produced by the above code segment for each of the following values for /* construct */ or state that the value violates the precondition of getValidAdjacentLocations. (Hint: Adjacent locations include diagonals.)

(a) new Location(0,2)
(b) new Location(3,0)
(c) new Location(4,5)
(d) null

See the Grid interface practice test solutions and explanations or review them with AP CS Tutor Brandon Horn.

AP CS A exploration of a change from GridWorld to labs

Authors: Renee L. CiezkiEstrella Mountain Community College, Glendale, Arizona, USA
Lien DiazCollege Board, Atlanta, Georgia, USA
Robert Glen MartinSchool for the Talented and Gifted, Dallas, Texas, USA
Henry M. WalkerGrinnell College, Grinnell, Iowa, USA
2013 Article
· Citation Count: 0
· Downloads (cumulative): 49
· Downloads (12 Months): 8
· Downloads (6 Weeks): 0

Published in:

· Proceeding
SIGCSE '13 Proceeding of the 44th ACM technical symposium on Computer science education
Pages 381-382

Denver, Colorado, USA — March 06 - 09, 2013
ACMNew York, NY, USA ©2013
table of contents ISBN: 978-1-4503-1868-6 doi>10.1145/2445196.2445310

active learningcase studiescomputer science educationcomputing applicationslaboratory exercisesmodel curricula

Powered by

The ACM Digital Library is published by the Association for Computing Machinery. Copyright © 2018 ACM, Inc.
Terms of Usage   Privacy Policy   Code of Ethics   Contact Us

One thought on “Gridworld Case Study Quick Reference Publishing

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *