All pastes #1593479 Raw Edit

Bug

public java v1 · immutable
#1593479 ·published 2009-10-05 01:18 UTC
rendered paste body
/** * 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;}