CS111, CS Dept, Wellesley College

Lab 3

Wednesday, September 17, 2007


Total checkmarks:

Go to the download directory on puma and download the lab3_programs directory to your desktop.

EXERCISE 1 - Another Java Execution Model Diagram

Below are the declarations for two classes: a ScooterWorld class that is a subclass of BuggleWorld and a ScooterBuggle class that is a subclass of Buggle.

public class ScooterWorld extends BuggleWorld { public void run () { ScooterBuggle sam = new ScooterBuggle(); ScooterBuggle sara = new ScooterBuggle(); Color c = Color.blue; sara.setColor(c); sam.scootLeft(4); sara.forward(4); sam.switchPositions(sara); sara.forward(8); sam.left(); sam.forward(8); sam.setColor(c); sam.scootRight(4); sara.setColor(Color.red); sara.left(); sara.forward(4); } } class ScooterBuggle extends Buggle { public void scootLeft (int steps) { this.left(); this.forward(steps); this.right(); } public void scootRight (int n) { right(); forward(n); left(); } public void switchPositions (Buggle b) { Location p = b.getPosition(); b.setPosition(this.getPosition()); this.setPosition(p); } }
Draw the Java Execution Model Diagram for the execution of SW1.run(). Follow the conventions and rules presented in lecture and given in Problem Set 2.

EXERCISE 2 - Bagel Rugs

On Problem Set 2, you've been introduced to the Buggle Baggle Ruggle Company. Here's a simpler rug that the buggles worked on before they came up with their more sophisticated design. Can you figure out how to put this rug together using the same guidelines as given in the problem set? The setup for this problem is in the LabRugWorld.java file.

Hints

Implementation of Checker Board Strategies

Your working grid should be 8x8 cells. The checkerboard you draw should be 8x8, also. Write your code in an incremental fashion. Your code should be written in a way to allow for different color checkerboards to be produced very easily.