CS111 PreLab 2

This prelab will help prepare you for the exercises we will be doing in Lab 2, in which we will be writing programs using methods.

Reminder: Prelab exercises do not involve the use of a computer. They should always be done on paper. You should not spend more than one hour on each week's prelab. The prelab must be turned in at the beginning of the lab section.

Task 1: Types of Methods

In lecture we learned about void and non-void methods and about methods with and without parameters. For the first part of the prelab, you should look at the Buggle Contract and sort all the methods in the five different classes (Buggle, BuggleWorld, Point, Color, and Direction) into the four possible categories. For non-void methods you should indicate what type of data it returns. For methods with parameters you should indicate what type of parameters it requires.

Print out (or copy) the sample chart. Some of the methods have been placed in the proper categories to get you started. For example:
forward(int) is a void method with one parameter. The parameter is an integer (represented by int).
Buggle() is a non-void method with no parameters. It returns a Buggle. We indicate this by writing Buggle Buggle() in the chart where we first indicate the type of data returned followed by the name of the method. All methods in the chart should be followed by a set of open and close parenthesis.

Note: Do not spend more than 10 minutes on this task.

Task 2: Writing Simple Java Code

On paper, write a program to draw the following pattern in a BuggleWorld grid when the run() method is invoked. Assume your starting position/heading is (1,1) facing EAST, and that your ending position is as shown. Use the Hi.java program from Lab 1 as a model.

For example, you would be provided with the following program:
public class CheckerWorld extends BuggleWorld {

  public void run () {

    // add your code here to draw the pattern

  }

}

Task 3: Writing a Method

On paper, write a method to accomplish the same task by adding code to the following program:

public class CheckerWorld extends BuggleWorld {
  public void run() {
    CheckerBuggle andy = new CheckerBuggle();
    andy.drawPattern();
  }
}

class CheckerBuggle extends Buggle {

  public void drawPattern() {

    // add your code here to draw the pattern

  }

}