import java.awt.Color; public class Bug { // ********************* constructors ************************* // default constructor public Bug() { color = Color.RED; direction = Location.NORTH; location = new Location(0, 0); } // other constructor public Bug(Color newColor, int newDirection, int row, int col) { color = newColor; // or setColor(newColor) direction = newDirection; // or setDirection(newDirection) location = new Location(row, col); } // ********************* accessor methods ************************* // gets the current color public Color getColor() { return color; } // gets the current direction public int getDirection() { return direction; } // gets the current location public Location getLocation() { return location; } // ********************* modifier methods ************************* // changes color public void setColor(Color newColor) { color = newColor; } // sets the current direction which is an angle between 0 and 359 degrees public void setDirection(int newDirection) { direction = newDirection % 360; } // sets the current location to a new location public void setLocation(int row, int col) { location = new Location(row, col); } // sets the current location to a new location public void setLocation(Location newLocation) { location = newLocation; } // ********************* interesting methods ********************** // Turns the bug 45 degrees to the right without changing its location. public void turn() { setDirection(getDirection() + 45); } // Moves the bug forward in current direction public void move() { if (direction == 0) { location.setRow(location.getRow() - 1); } else if (direction == 45) { location.setCol(location.getCol() + 1); location.setRow(location.getRow() - 1); } else if (direction == 90) { location.setCol(location.getCol() + 1); } else if (direction == 135) { location.setCol(location.getCol() + 1); location.setRow(location.getRow() + 1); } else if (direction == 180) { location.setRow(location.getRow() + 1); } else if (direction == 225) { location.setCol(location.getCol() - 1); location.setRow(location.getRow() + 1); } else if (direction == 270) { location.setCol(location.getCol() - 1); } else if (direction == 315) { location.setCol(location.getCol() - 1); location.setRow(location.getRow() - 1); } } // ********************* properties ******************************* private Location location; // row, col private int direction; // angle measurement between 0 and 359 private Color color; // built-in colors like Color.RED }