download
directory on nike and download the lab3_programs
directory to your desktop.
ScooterWorld
class that is a subclass of BuggleWorld and a ScooterBuggle
class that is a subclass of Buggle.
Let's say we have an instance of
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); } }
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.
LabRugWorld.java
file.
Hints
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.
1) RowBuggle |
3) LBuggle |
4) SpiralBuggle |
5) MazeBuggle |