Ice01 Getting Started With Java and Robots using jGRASP

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 his-or-her own copy.

ICE ICE 01 Part 1: Errors in Programs

In addition to robots and things, the Robot's city can also contains walls. To add a wall to the city, use the command

new Wall(city_name, street#, avenue#, direction);

For example, to add one wall you would modify the Starting_Template.java with a snippet like the one shown below. Remember that avenues are those roads that go north-south Up-Down and streets are those roads that go east-west Left-Right.

City toronto = new City();

Robot Jo = new Robot(toronto, 3, 0, Direction.EAST, 0);

new Thing(toronto, 3, 2);

new Wall(toronto, 3, 1, Direction.EAST);

Jo the Robot will break if it runs into a wall (see images below).

Initial State Final State - SPLAT!
Starting Final

You should try adding the above code, and make sure that when you run your program, the robot crashes into the wall. Notice how the program will blindly crash the robot, rather than fixing this mistake. Since the Java language will happily, blindly crash your program for you, you'll have to fix this error yourself, which is exactly what you'll do in the next section.

When you get done with this exercise, go on to the next section. Go Next

ICE ICE 01 Part 2: Get Jo Around the Wall

For this in-class exercise, write the code to pick up the thing and put it down again as in the first example, but this time moving Jo around the wall. First save the Starting_Template.java file with a new name: ICE_1.java. When you change the file name of a Java program, you must also change the public class name (see the code sSnippet below) otherwise the code will not compile.

The source code inside:


public class ICE_1 extends Object
{
    public static void main(String[] args)
   {
       City toronto = new City();

       Robot Jo = new Robot(toronto, 3, 0, Direction.EAST, 0);

       new Thing(toronto, 3, 2);
   }

}

Work with a partner to write code that moves Jo from the initial state to the final state as shown below:

Initial State Final State - Success!
Start Stop

When you get done with this exercise, show your Instructor, then go on to the next section. Go Next

ICE ICE 01 Part 3: A More Complicated Example

First, download the file ICE_01_03.java from the course website.

Open this in JGrasp, compile it, and run it.

You'll notice that the program doesn't actually do anything, but that you do see the initial state, as pictured in below.

You should then add the Java source code needed to move Jo from the Initial state, to the Final state (as shown below).

Initial State Final State - Success!
Start Final

When you get done with this exercise, show your Instructor, then go on to the next section. Go Next

ICE ICE 01 Part 4: Yet Some More Complexity

First, download the file ICE_01_04.java from the course website.

Open this in JGrasp, compile it, and run it.

You'll notice that the program doesn't actually do anything, but that you do see the initial state, as pictured below.

You should then add the Java source code needed to move Jo from the Initial state, to the Final state (as pictured below).

Initial State Final State - Success!
Start Final

When you get done with this exercise, show your Instructor.