CS111 PreLab 3

  1. Answers

Task 1: Understanding Buggle Code

Task 2: Java Execution Model Diagram

Available in hardcopy outside Professor Turbak's office.

Task 3: Writing a method with parameters

public class CheckerWorld extends BuggleWorld {
  public void run() {
    CheckerBuggle andy = new CheckerBuggle();
    andy.drawPattern(Color.red);
    andy.drawPattern(Color.blue);
    andy.drawPattern(Color.yellow);
    andy.drawPattern(Color.black);
  }
}
 
class CheckerBuggle extends Buggle {
 
  public void drawPattern(Color c) {
    this.setColor(c);
    this.brushUp();
    this.forward();
    this.brushDown();
    this.forward();
    this.brushUp();
    this.left();
    this.forward();
    this.brushDown();
    this.backward();
    this.right();
    this.brushUp();
    this.forward();
    this.brushDown();
    this.forward();
    this.left();
  }
 
}