/** * Creates a class Bug that moves a bug 1 unit per move. */ public class Bug { /** * Constructs a bug with a starting point. * @param initialPosition The original position of the bug. */ public Bug(int initialPosition) { position = initialPosition; } /** * Turns the bug so that it moves in the opposite direction. */ public void turn() { x = -1 * x; } /** * Moves the bug 1 unit in the direction it is facing. */ public void move() { newPosition = position + x; position = newPosition; } /** * Returns the current position of the bug. */ public int getPosition() { return position; } private int position; private int newPosition; private int x = 1; }