/* FILE NAME: GohomeWorldSolns.java * AUTHOR: Stella * WHEN: Oct 1, 2007 * WHAT: For the purpose of Lab5, F07: * Task 1, Debugging GohomeWorld. * This version contains bugs! * MODIFICATION HISTORY: * Based on WallHuggerWorld from lecture */ import java.awt.*; public class GohomeWorldSolns extends BuggleWorld { public void run () { GohomeBuggle bubba = new GohomeBuggle(); //this should be a GohomeBuggle, // not a plain old Buggle bubba.setPosition(new Location(7, 6)); //need to use the Location constractor bubba.tick128(); } //--------------------- // The following main() method is needed to run the applet as an application public static void main (String[] args) { runAsApplication(new GohomeWorldSolns(), "GohomeWorld Solutions"); } } //nedded to close the GohomeWorldSolns class //************************************************************** class GohomeBuggle extends TickBuggle { public void followWall() { if (isFacingWall()) { left(); } else { forward(); } } //this is needed to close the followWall() method public void tick() { //several errors were fixed in the following line //getPosition().y=1: the "=" does not check for equality. "==" is nedded // "&" should be replaced by "&&" //some parens are needed to correct the expression if (!((getPosition().x==1) && (getPosition().y==1))){ followWall(); //the () are needed, since followWall() is a method //also, the capitalization on the methods name was not correct } } //nedded to close the tick() }