New Robots With New Commands / Services / Methods / Functions / Subroutines / Routines

 

Note:  Please keep the programs that you create today, in case you have a question about your grades for the ICEs at the end of the quarter. When you're working with a partner, each person should save their own, individual copy.

 

 

ICE 1: Code Tracing

            Download the following file from the course website, and trace through it.

 

·        ICE_03_01_Trace.java
(This is a bit more complex, but you should be able to trace it just fine using the table)

 

If you get done with the above exercise, then go on to ICE 11.  If you haven’t yet heard the explanation for the syntax, then give it your best shot, and see what you can figure out on your own.

 

 

ICE 2: Finding Errors

When you try using any new feature of a computer programming language, you'll end up making many mistakes.  Some will be conceptual, and some will be purely not knowing what to type.  For this part of the In Class Exercises, you'll download a file from the website ICE_03_02_CompileErrors.java, and work with a partner to find all the errors that you can.  In order to get this done, you're welcome to refer to any books, handouts, or any other person if it'll help you find what's wrong.  However, by the time you get to ICE 12, you should know and understand any of these errors, so that if you make them on your own, you can fix them on your own.

 

            Further, once you've found five or more errors in the source code, you should raise your hand, so the instructor can check one or more.  You should record each bug in following format:

 

Line #

What's the problem?

Text Before/After You Fixed It

Type Of Error

13

Missing semi-colon: the Java language requires that each command ends in a semi-colon, and so the program won't compile without it.  I fixed the problem by adding a semi-colon

Before: this.turnLeft()

After: this.turnLeft();

Syntax / Compile-Time Error

Etc.

 

         

 

 

ICE 3: Write Code – Walk down a wall

            Use the city set-up given in ICE_03_03_WalkDownWalls.java  as a starting point. Create a new type of robot that knows how to walk down a wall three spaces tall (code a new service called walkDownWall.) The new service should leave the robot facing in the same direction as when it started. Recall that you can add more than one service to a new type of robot so feel free to also include (and use) the turnRight service that was described in part 1. This can make your code more readable, but is not required. The initial and final state of the program is shown in Figure 1)

 

            Feel free to try this problem on your own.  If you'd like guidance, consult the flowchart that's located on the final page of this I.C.E.

 

Initial State

Final State

Figure 7

            Instead of creating everything yourself from scratch, you should instead focus on translating the following flowcharts pictured in Figure 1 into Java.  This will allow you to focus on finding compiler and intent errors in the code, and will also provide you with an example of how to write decent code (decent, at least according to your humble instructor J ).

 

Figure 8: Flowcharts for the exercises