Homework 2: class extensions and conditionals

This homework assignment has three sections: a trace table, a debugging problem, and a coding challenge. You will hand in

Note: I will accept trace tables and debug tables as documents, open-office docs, excel files, or pdfs. I can not read .pages documents, so please do not submit in that form.

This homework should be done individually.

Part 1, Trace Table

Please complete a trace table for A2_Trace_2.java. You may start with the trace table here.

You should trace each object, including all of the walls. You should have a boolean column to document the state at conditionals. If you find any compile time errors, please fix them and then continue. If you find any intent errors, please stop tracing at that point and document the cause of the error.

Part 2, Debugging

Download the Diving.java program source code from the website. The program is supposed to make Jo The Robot perform diving acrobatics as shown below but it's not yet working. There are some intent errors in addition to some compile time errors. Find, document, and correct all the errors in the code in order to get Jo into the pool. Your program needs to look identical to the Initial State picture below and on the left, must then follow the blue line drawn on the Initial State picture, and must finish looking identical to the picture on the right (Final State).

Initial State

Final State

You may start with the Debug table on the course web page. You must include all the compile and intent errors, with fixes and labels. You should rename this document Diving.doc.

Part 3, Write some code

A Collecting Robot

You can complete this code by downloading CollectingBot.java, and should turn in this file when it is completed.

The program will begin as pictured below. You need to write code that will make the robot pick the Things up, and put the Things in the final row of the city, and end up with the city looking like it does in the following figure. HOWEVER, you want to design the robot so that it will work for any city that has the four horizontal 'pipes' (each containing a Thing), no matter how long those pipes are. The program that you're provided will randomly pick a width (within a reasonable range) so that you can make sure that your program runs properly in a variety of circumstances.

Note that for this assignment you should create a new type of robot to accomplish this task, and you should do so by creating new, reusable commands. I recommend thinking about something like 'moveToWall()', and 'moveToNextRow()'

Figure 3.1: Two examples of how the city may look when the program starts

Figure 3.2: Two examples of how the city should look when the program ends