![]() |
Lab 3
|
Go to the download
directory on puma 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.
Draw the Java Execution Model Diagram for the execution 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) { Location p = b.getPosition(); b.setPosition(this.getPosition()); this.setPosition(p); } }
SW1.run()
. Follow the conventions and rules
presented in lecture and given in Problem Set 2.
LabRugWorld.java
file.
Hints
Starting code for this excercise can be found in LabRugWorld.java
file,
within the lab_programs
folder you downloaded.
We can draw the checker board in many different ways, following different drawing strategies. A couple of those strategies are shown below.
Square Checker Board
In this approach, we draw the checkerboard by drawing 2 x 2 pieces, one at a time.
Here is such a piece, in black and red, as an example:
L Checker Board
This time we draw the checkerboards by finishing L-shaped pieces one at a time.
As an example, here is such a piece in black and red:
Spiral Checker Board
If you were curious, here is one more approach, to draw the checkerboards:
Can you think of any others?
Square Checker Board
CheckerBoardSquare.java
draw2x2Square()
draw2x2Square()
in order to do so? You shouldn't!!
Only the way the method is invoked should change!
draw4x4Square()
, to draw a 4 x 4 square. This method will
use the previously defined and tested draw2x2Square()
method.
draw4x4Square()
)
L Checker Board
You can find starting code for the L Checker Board approach,
in the file CheckerBoardL.java