Other 2016 FR Questions FR other years Be Prepared Home
A-3
Part (a)
  private boolean toBeLabeled(int r, int c, boolean[][] blackSquares)
  {
    return !blackSquares[r][c] &&
        (r == 0 || blackSquares[r-1][c] || c == 0 || blackSquares[r][c-1]);
  }


Part (b)
  public Crossword(boolean[][] blackSquares)
  {
    int rows = blackSquares.length;
    int cols = blackSquares[0].length;

    puzzle = new Square[rows][cols];
    int num = 1;

    for (int r = 0; r < rows; r++)
    {
      for (int c = 0; c < cols; c++)
      {
        if (toBeLabeled(r, c, blackSquares)) 1
        {
          puzzle[r][c] = new Square(false, num);
          num++;
        }
        else
          puzzle[r][c] = new Square(blackSquares[r][c], 0);
      }
    }
  }
Notes:
  1. Notice that toBeLabeled is a method of Crossword, not Square.  Therefore, toBeLabeled can be called in the Crossword's constructor without any prefix.  The question does not specify any methods of Square.

Other 2016 FR Questions | Back to Contents

Copyright © 2016 by Skylight Publishing
support@skylit.com