Copyright © Cay S. Horstmann, Kathleen O’Brien 2009-2014
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
This lab has been adapted from a lab authored by Kent Beck at SDSU.
Carol the robot moves along the lines of a grid. Here, we denote her position with an arrow whose tip points to the direction in which she moves. (This is just for diagramming purposes. You'll see later how she actually looks.)
She can carry out the following five operations:
However, if you try to move Carol into a wall, she “crashes” (turns black and ceases to function). Don't do this.
true
if there is a wall or window directly in front of the robot, false
otherwise. (Her front sensor is a touch sensor that can't tell the difference between a wall or window)true
if there is a wall directly to the right of the robot, false
otherwise. (Her side sensor is an optical sensor that can't tell the difference between a window and empty space.) Carol has been placed into a rectangular room with a single window. The width and depth of the room, the position of the window, and Carol's position can be arbitrary. The following program has been designed to position Carol next to the window.
The program is presented in flowchart notation. The rectangles are actions to take. The hexagons denote method calls.
The scribe calls out the steps from the flowchart. The driver moves the robot on a sheet of paper, following the instructions given by the scribe.
Question: In step 1, you should have successfully completed the program. (That is, Carol should have found the window and stopped beside it.) However, there can be many different starting situations—that is, different positions for the window and different starting locations for Carol. There is at least one starting situation for which the program does not work correctly. Can you find it? Is there more than one such problem situation? (Try different locations for the window and different starting positions for Carol. Use pencil and paper for sketches!)
What does the program do?
run
method and modify the call to makeRoom
so that the window is on the left wall. How did you do that? Hint: You specify the center point of the window. (This means you change the values you pass to the method when you call it in RobotTest.java. DO NOT change the makeRoom method) Scribe: What is the call that you used?makeRoom
so that the window is on one of the problem situations you identified in part A. ( Remember not to change the makeRoom method) Scribe: What is the call that you used?findWindow
method. Apply the fix that you identified in part A. Driver: What is your fix in Java code?