CS111 Lab 4

EXERCISE 1: Invocation Tree

Given the following code below, draw an invocation tree for [LBW1].run(), where [LBW1] is an instance of LabBuggleWorld in Object Land.

public class LabBuggleWorld extends BuggleWorld { public void run () { LabBuggle barb = new LabBuggle(); Color c = Color.blue; barb.forward(2); barb.turnAround(); barb.jump(2,3); barb.colorTwo(c.darker()); barb.isOverBagel(); } } class LabBuggle extends Buggle { public void turnAround () { this.left(); this.left(); } public double jump (int right, int up) { Point p = this.getPosition(); this.setPosition(new Point(p.x+right, p.y+up)); return this.distanceFromStart(); } public double distanceFromStart () { Point p = getPosition(); int x = p.x-1; int y = p.y-1; return Math.sqrt((x*x)+(y*y)); } public void colorTwo (Color c) { forward(); setColor(c); backward(); } }

EXERCISE 2: Escher Knitting Patterns

Read about the Escher knitting patterns from Problem Set 3. Below are three practice knitting patterns to figure out. The skeletons for the methods are in the LabKnitWorld.java file.

labKnit1(Color.red, Color.green)

labKnit2(Color.magenta, Color.blue)

labKnit3(Color.blue, Color.red,
Color.cyan, Color.magenta)
 
Note: The patterns above can be viewed by loading the LabKnitWorld.html file in the Test folder.

EXERCISE 3: Simple QuiltWorld Patterns

Read about QuiltWorld in Problem Set 3. Below are two simpler quilt designs to figure out. The skeletons for the methods are in the LabQuiltWorld.java file.

diamonds()

fourColors()
Note: The patterns above can be viewed by loading the LabQuiltWorld.html file in the Test folder.