# Crossword free response answer 2016

`Crossword` is #3 from the from the 2016 AP Computer Science A Free Response problems.

https://secure-media.collegeboard.org/digitalServices/pdf/ap/ap16_frq_computer_science_a.pdf

## Part (a) `toBeLabeled` method

``````private boolean toBeLabeled(int r, int c, boolean[][] blackSquares)
{
if(blackSquares[r][c])
return false;

if(r == 0 || blackSquares[r - 1][c])
return true;

if(c == 0 || blackSquares[r][c - 1])
return true;

return false;
}
``````

It is not acceptable to write the opposite checks and return false. The problem specifies that either or both of the conditions could be true for the square to be labeled.

Outside of an exam setting I would write this as:

``````return ! blackSquares[r][c] && (r == 0 || blackSquares[r-1][c] || c == 0 || blackSquares[r][c-1]);
``````

## Part (b) `CrossWord` constructor

``````public Crossword(boolean[][] blackSquares)
{
puzzle = new Square[blackSquares.length][blackSquares.length];

int num = 1;

for(int r = 0; r < puzzle.length; r++)
{
for(int c = 0; c < puzzle.length; c++)
{
if(toBeLabeled(r, c, blackSquares))
{
puzzle[r][c] = new Square(false, num);
num++;
}
else
puzzle[r][c] = new Square(blackSquares[r][c], 0);
}
}
}
``````

It is very common for students to miss the first line of this constructor. Setting elements in an array (or adding to a list) is not the same thing as initializing the variable.