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.
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.
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.
public class CheckerWorld extends BuggleWorld { public void run () { // add your code here to draw the pattern } }
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 } }