# quiz9 - () Sprite getSprite (Location loc) //returns null...

This preview shows pages 1–3. Sign up to view the full content.

1 Name: ____________________ Section: M N O P Dave's 15-100 March 25, 2009 Quiz 9 1. The robot is in the space marked "Robot" in the world shown below: The table below describes 6 scenarios, in which the robot is initially facing the given direction, and then the given code segment is executed. For each scenario, indicate the robot's final direction after the code segment has executed. Initial Direction Code Segment Final Direction east while ( ! Robot.frontIsClear()) { Robot.turnLeft(); } south while ( ! Robot.frontIsClear()) { Robot.turnLeft(); } east do { Robot.turnLeft(); } while ( ! Robot.frontIsClear()); south do { Robot.turnLeft(); } while ( ! Robot.frontIsClear()); north for (int i = 0; i <= 2; i++) { Robot.turnLeft(); } north for (int i = 3; i > 1; i--) { Robot.turnLeft(); }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Reference Location Class Location (int row, int col) int getRow () int getCol () boolean equals (Location otherLoc) World Class World (int numRows, int numCols) int getNumRows () int getNumCols
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: () Sprite getSprite (Location loc) //returns null if empty Sprite Class Sprite () Location getLocation () void putSelfInWorld (World w, Location loc) void removeSelfFromWorld () 2. Implement the method isAtLoc , which should return true if s is located at loc , and false if s is located somewhere else. (You should assume that s has already been put into some world.) public static boolean isAtLoc(Sprite s, Location loc) { 3 3. Implement the method makeEmpty , which should remove whatever sprite is at loc . If there is no sprite at loc , then makeEmpty should do nothing. public static void makeEmpty(World w, Location loc) { 4. Implement the method removeAll , which should remove all sprites from the given world. Your solution should call makeEmpty where appropriate. You should assume that makeEmpty has been correctly implemented (in the same file as removeAll ), regardless of what you wrote in the previous question. public static void removeAll(World w) {...
View Full Document

## quiz9 - () Sprite getSprite (Location loc) //returns null...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online