EECS2030 C & E Test 1D Solution

  1. ChessSquare_solution1.java
  1. ChessSquare_solution2.java

ChessSquare.java Solution 1

This solution uses a char field to represent the rank, a char field to represent the file, and a a String field to represent the piece. Because char is an integer type in Java, arithmetic can be used to subtract ranks and subtract files to determine adjacency and connectivity between squares.

ChessSquare.java Solution 2

This solution uses String fields to represent the rank, file, and piece. This representation complicates the computation of adjacency and connectivity. One solution is to create a string containing all of the files (in order from a to h) and a string containing all of the ranks (in order from 1 to 8). The index of a specified file or rank can be determined using the string method indexOf; arithmetic can then be used to subtract rank indices and subtract file indices to determine adjacency and connectivity between squares.