Robot Recursion

10 points

Check out an informative example of solving a problem with recursion. Read section 7.2, 'More on Recursion', here: Karel7.2.htm. You want to look particularly at the example in which the robot is trying to locate a mine. This involves the 'findMine()' method.

Here is your task. The user places a robot on an arbitrary corner, say the corner of 11th Street and 8th Avenue. Your task is to place a beeper at the corner of 1st Street and 8th Avenue, and a beeper at the corner of 11th Street and 1st Avenue. Here is a picture of the robot, initially positioned at 11th Street and 8th Avenue, after completing this task:


Note that, when he is done, he is back where he started. You need to write a recursive solution to this problem.

The program is set up so that the user interactively chooses the robot's initial position. I used Java graphical user interface (GUI) tools, and threads, to make this work. You do not need to understand how to build GUIs or use threads for the AP Exam, but you certainly can read about them if you want to. Here is a picture of the GUI that the user sees upon running the program:

Descriptions of what code you need to write are in the 3 Java source files that you download below.

 

Starting Point

You can download RectangleFrame.java, RecursiveRobot.java and RobotThread.java to use as starting points in writing your program. Right-click on the links, choose 'Save Target As' and add the '.java' extension to each file name.

 

Credit

This programming assignment is problem 7.5 in Karel J. Robot, A Gentle Introduction to the Art of Object-Oriented Programming in Java by Joseph Bergin, Mark Stehlik, Jim Roberts and Richard Pattis. Chapter 7 of this book can be found here: Karel7.htm.