Help with java project. Im so close!
So my project is to:
Write a class ZBug to implement bugs that move in a “Z” pattern, starting in thetop left corner. After completing one “Z” pattern, a ZBug should stop moving.In any step, if a ZBug can’t move and is still attempting to complete its “Z”pattern, the ZBug does not move and should not turn to start a new side. Supply the length of the “Z” as a parameter in the constructor. The following image shows a “Z” pattern of length 4. Hint: Notice that a ZBug needs to be facingeast before beginning its “Z” pattern.
I am really close to being done but for some reason my zbug doesnt complete the end of the z. Also im not sure if it will stop once it is done? Can anyone help? Here is my code for ZBug.java:
public class ZBug extends Bug
private int steps;
private int sideLength;
private int moveCount;
* Constructs a box bug that traces a square of a given side length
* @param length the side length
public ZBug(int length)
steps = 0;
sideLength = length;
* Moves to the next location of the square.
public void act()
if (steps < sideLength && canMove())
//else if moveCount=(3*sideLength)
if (steps==sideLength && getDirection()==90)
steps = 0;
else if (steps==sideLength && getDirection()==225)
And here is my code for ZBugRunner.java:
* This class runs a world that contains box bugs. <br />
* This class is not tested on the AP CS A and AB exams.
public class ZBugRunner extends BugRunner
public static void main(String args)
ActorWorld world = new ActorWorld();
//ZBug alice = new ZBug(6);
ZBug bob = new ZBug(3);
//world.add(new Location(7, 8), alice);
world.add(new Location(5, 5), bob);