1  public class Bug
  2  {
  3     private int row;
  4     private int column;
  5     private int direction; // 0 = North, 1 = East, 2 = South, 3 = West
  6     
  7     public void moveOneUnit()
  8     {
  9        final int NORTH = 0;
 10        final int EAST = 1;
 11        final int SOUTH = 2;
 12        final int WEST = 3;
 13        
 14        if (direction == NORTH) { row--; }
 15        else if (direction == EAST) { column++; }
 16        else if (direction == SOUTH) { row++; }
 17        else if (direction == WEST) { column--; }
 18     }
 19  
 20     public void turnRight() 
 21     {
 22        int DIRECTIONS = 4;
 23  
 24        direction++;
 25        if (direction == DIRECTIONS) { direction = 0; }
 26     }
 27  
 28     public int getRow() { return row; }
 29     public int getColumn() { return column; }
 30  }