GridWorld Manual Multiple Choice Test Preparation for the AP Computer Science Examination This test includes program segments, which are not complete programs. Answer such questions with the assumption that the program segment is part of a correct program. Furthermore, assume that all required import statements are available. These are sample multiple choice questions from a 100-questions GridWorld test 08. How many classes and objects are shown on the grid display to the left? (A) (B) (C) (D) (E) 2 classes and 8 objects 8 classes and 2 objects 3 classes and 5 objects 5 classes and 3 objects 3 rocks and 5 bugs 09. How many classes and objects are shown on the grid display to the left? (A) (B) (C) (D) (E) 3 classes with 4 objects 4 classes with 3 objects 4 classes with 12 objects 12 objects with 4 objects 3 rocks, 3 bugs, 3 actors and 3 flowers Chapter IX GridWorld Case Study Comprehensive Test 239 17. Consider the following program segment. ActorWorld world = new ActorWorld(); Actor actor1 = new Actor(); Bug bug1 = new Bug(); world.add(new Location(5,5),actor1); world.add(new Location(1,1),bug1); Where will the bug1 object be placed on the GridWorld ? (A) (B) (C) (D) (E) At location (5,5) and will replace any object at the location if the cell is occupied At location (5,5) only if the cell is not occupied. At a random location on the grid At location (1,1) and will replace any object at the location At location (1,1) only if the cell is not occupied. 18. Which of the following program statements constructs two anonymous objects? (A) (B) (C) (D) (E) world.add(new Location(1,1),actor1); world.add(new Bug()); world.add(new Location(1,1),new Rock()); All of the above A and C only 19. Consider the following GridWorld main method. public static void main(String[] args) { ActorWorld world = new ActorWorld(); Bug bug1 = new Bug(); Bug bug2 = new Bug(); world.add(new Location(0,4),new Rock()); world.add(new Location(9,7),new Rock()); world.add(new Location(0,0),bug1); world.add(new Location(5,5),bug2); world.show(); } 20. Consider the following GridWorld main method. public static void main(String[] args) { ActorWorld world = new ActorWorld(); Bug bug1 = new Bug(); Bug bug2 = new Bug(); world.add(new Location(0,6),new Rock()); world.add(new Location(9,7),new Rock()); world.add(new Location(0,0),bug1); world.add(new Location(5,5),bug2); world.show(); } 240 What is the cell location of bug1 after 5 steps? (A) (B) (C) (D) (E) (0,3) (1,3) (1,4) (1,5) (2,5) What is the cell location of bug2 after 7 steps? (A) (B) (C) (D) (E) (0,6) (0,5) (1,5) (0,4) (1,9) GridWorld Case Study Manual in Preparation for the AP Computer Science Examination 39. Consider the following new class declaration for a GWCS program. public class Shark extends Rock { } Shark objects will (A) (B) (C) (D) (E) act like Rock objects. look like Rock objects. just sit in the Grid and do absolutely nothing. be an obstacle for moving Bug objects. All of the above 43. Consider the following GridWorld display. This display shows (A) that four methods are defined in the Bug class. (B) that three methods are re-defined in the Bug class. (C) that one methods is newly-defined in the Bug class. (D) that the Actor class uses inherited methods of the Bug class. (E) all of the above. 45. Consider the following act method definition. This act method definition is a member of the __________ class. public void act() { if (can Move()) move(); else turn(); } 65. Consider the DizzyBug class definition. public class DizzyBug extends Bug { public boolean canMove() { return false; } } (A) (B) (C) (D) (E) Actor Rock Flower Bug Critter What is true about behavior of the Dizzy Bug objects? DizzyBug objects (A) (B) (C) (D) (E) re-define the act method. behave differently from Bug objects without re-defining the act method. behave the same as Bug objects, because the act method is not re-defined. simply spin in place. B and D. Chapter IX GridWorld Case Study Comprehensive Test 241 67. Which of the following statements describes the act behavior of a Critter? (A) (B) (C) (D) (E) Gets an array of neighbors. Processes each member of the neighbor array. Gets an array of empty adjacent cells. Moves to a random location in the empty cells array. All of the above 70. Consider the GridWorld display on the bottom-right in the middle of program execution. The two objects with a tail are Critter objects. After the next step iteration, how many Bug objects will be left? (A) (B) (C) (D) (E) 242 1 bug 2 bugs 3 bugs 4 bugs 5 bugs GridWorld Case Study Manual in Preparation for the AP Computer Science Examination