CS111 Lab 3 -- Spring 2000

Go to the download directory on nike 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) { Point p = b.getPosition(); b.setPosition(this.getPosition()); this.setPosition(p); } }
Let's say we have an instance of ScooterWorld in Object Land. We will label it SW1. 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 3. In particular, all objects should be drawn in Object Land except for instances of the Direction class. Use reference labels to refer to instances in Object Land instead of using pointers.

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


EXERCISE 3 - Checkerboards

Scenario
Today in lab you are going to help Buggles ben and barb figure out how to draw a checkerboard. They've brainstormed a lot of possible ways to draw out a checkerboard in BuggleWorld. Your job is to figure out which idea of theirs is best.

We will be creating a CheckerBuggle which will draw the checkerboard in all these different ways. For each strategy, fill in the corresponding makeCheckerBoardXXX method. You should try to implement the strategy using the least amount of code possible. "Code" is counted as the number of method calls in your extended Buggle class.

Restrictions: Every Buggle starts at (1,1). You can not use setPosition() or setHeading(). The checkerboard will be black and red. The first square (1,1) is black.

Hints: Try to look for patterns that repeat. Start with small patterns and build up in complexity. Patterns that are used repeatedly are good bets for abstracting into your own custom made methods.

Checker Board Strategies

1) RowBuggle
RowBuggle creates checkerboards by moving back and forth across the board horizontally. RowBuggle first moves to the right. Fill in the makeCheckerBoardRows method.

SquareBuggle
2) SquareBuggle creates checkerboards by finishing 2 x 2 pieces of the checkerboard one at a time. makeCheckerBoardSquare

square

3) LBuggle
LBuggle creates checkerboards by finishing L-shaped pieces one at a time. makeCheckerBoardL
L

4) SpiralBuggle
SpiralBuggle creates checkerboards by moving in a counter-clockwise spiral around the checkerboard from the outside in. makeCheckerBoardSpiral

5) MazeBuggle
MazeBuggle creates checkerboards by moving in concentric squares starting at (1,1) and working outwards. MazeBuggle first moves to the right.makeCheckerBoardMaze