/** * Class to represent a grid of partially plowed city streets * and a single snowplow that is charged with clearing them. * * @author David Liben-Nowell (for CS117 Winter 2006, Carleton College) * @author (your name here) * @version 13-Feb-2006 * */ class Snowplow { // Here's an example grid of city streets for reference in the // description of the object variables below: // // +------+------+------+ /|\ // | | | * | // | | | * north // | | | * // +------+------+------+ // | | | * // | | | * // | | | * // +------+------+------P // | | | * // | | | * south // | | | * | // +------+------+------+ \|/ // the number of blocks per side of the grid of streets (3 in the example) private int gridSize; // clearedNS[row][col] indicates whether the corresponding street // running north-south in the grid has already been plowed. // Thus clearedNS is gridSize rows by (gridSize + 1) columns (3-by-4 above) private boolean[][] clearedNS; // clearedEW[row][col] is analogous for east-west streets. // clearedEW is (gridSize + 1) rows by gridSize columns (4-by-3 above) private boolean[][] clearedEW; // the current (row,col) position of the snowplow in terms of the grid // of intersections. Thus 0 <= x,y <= gridSize. (If the plow // were at the point marked "P" in the example, we'd have row=2, col=3.) private int row; private int col; /** * Snowplow constructor. Sets up the grid of streets, initializes all * streets to "unplowed" (i.e., cleared==false). * @param size the number of blocks on a side of the grid of streets. * @param depotRow the row in which the snowplow starts. * @param depotCol the column in which the snowplow starts. */ public Snowplow(int size, int depotCol, int depotRow) { // ... } /** * Accessor for the snowplow's position. */ public int[] getPosition() { int pos[] = {row, col}; return pos; } /** * Returns true if and only if all of the streets are plowed. */ public boolean allPlowed() { // ... return false; } // Missing functionality: provide some mechanism for the snowplow // to move through the streets, clearing any unplowed streets that // it goes by, one block at a time. You can accomplish this in // many ways, and it's up to you to choose the one that you like // the best. Spend time talking over this decision with your // partner before you start coding. Don't feel shy about asking // the group next to you to discuss it as well. /** * Returns a representation of the Snowplow object as a String. * Distinguishes between plowed ("---") and unplowed ("***") * streets, and shows the location of the plow itself. The * example shown in the comments at the very beginning of this * class is the result of toString(). */ public String toString() { // think through this method before you try to code it. you // may want to consider breaking out some pieces of // functionality into separate (private) methods. // ... return ""; } }