1  /**
  2     A queen in the eight queens problem.
  3  */
  4  public class Queen
  5  {
  6     private int row;
  7     private int column;
  8  
  9     /**
 10        Constructs a queen at a given position.
 11        @param r the row 
 12        @param c the column
 13     */
 14     public Queen(int r, int c)
 15     {
 16        row = r;
 17        column = c;
 18     }
 19  
 20     /**
 21        Checks whether this queen attacks another.
 22        @param other the other queen
 23        @return true if this and the other queen are in the same
 24        row, column, or diagonal.
 25     */
 26     public boolean attacks(Queen other)
 27     {
 28        return row == other.row
 29           || column == other.column
 30           || Math.abs(row - other.row) == Math.abs(column - other.column);
 31     }
 32  
 33     public String toString() 
 34     { 
 35        return "" + "abcdefgh".charAt(column) + (row + 1) ; 
 36     }
 37  }