// file: Pair.java // author: Robert Keller // purpose: Represent a pair of row, column coordinates on a grid. /** * A Pair maintains a pair of int's, row and col. These are publicly * accessible. */ class Pair { public int row; public int col; /** * Create a Pair from row and Column. */ Pair(int row, int col) { this.row = row; this.col = col; } /** * Indicate whether this Pair is adjacent on the Grid to the argument Pair. */ public boolean adjacent(Pair other) { return (row == other.row && (col == other.col-1 || col == other.col+1)) || (col == other.col && (row == other.row-1 || row == other.row+1)); } /** * Equality test for Pairs. */ public boolean equals(Pair other) { return row == other.row && col == other.col; } /** * Provide a String representation of this Pair. */ public String toString() { return row + " " + col; } }