CS111 PreLab 2 Answers

Task 1: Types of Methods

Buggle class
void methods non-void methods
w/o parameters with parameters w/o parameters with parameters
forward()
backward()
left()
right
brushDown()
brushUp()
dropBagel()
pickUpBagel()
forward(int)
backward(int)
setPosition(Point)
setHeading(Direction)
setColor(Color)
Buggle Buggle()
Point getPosition()
Direction getHeading()
Color getColor()
String toString()


BuggleWorld class
void methods non-void methods
w/o parameters with parameters w/o parameters with parameters
run()



Point class
void methods non-void methods
w/o parameters with parameters w/o parameters with parameters


String toString() Point Point(int,int)
boolean equals(Point)

Color class
void methods non-void methods
w/o parameters with parameters w/o parameters with parameters


Color brighter()
Color darker()
int getRed()
int getGreen()
int getBlue()
String toString()
Color Color(int,int,int)
Color Color(float,float,float)
boolean equals(Color)

Direction class
void methods non-void methods
w/o parameters with parameters w/o parameters with parameters


Direction left()
Direction right()
Direction opposite()
String toString()
boolean equals(Direction)

Task 2: Writing Simple Java Code

public class CheckerWorld extends BuggleWorld {

  public void run () {
    Buggle andrea = new Buggle();
    andrea.brushUp();
    andrea.forward();
    andrea.brushDown();
    andrea.forward();
    andrea.brushUp();
    andrea.left();
    andrea.forward();
    andrea.brushDown();
    andrea.backward();
    andrea.right();
    andrea.brushUp();
    andrea.forward();
    andrea.brushDown();
    andrea.forward();
    andrea.left();
  }

}

Task 3: Writing a Method

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

class CheckerBuggle extends Buggle {

  public void drawPattern() {
    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();
  }

}