Limited access

Upgrade to access all content for this subject

A rectangular puzzle exists with all pieces being identically-sized squares. The main part of the puzzle has a total of 600 pieces and each row of this main part of the puzzle is 30 pieces wide.

Additionally, there is a border of artistic icons completely surrounding this main puzzle area, and this border is exactly one piece wide, with each piece of the border being the same size as a main puzzle piece. Finally, at the bottom of the puzzle is one additional row of square pieces that spells out the title of the puzzle.

The puzzle is composed of all the before-mentioned pieces, each piece being square and the same size. The PuzzlePiece class is defined as follows:

public class PuzzlePiece 
{
    private Image image;  // Image represented by this piece
    private int row;      // row where this piece goes
    private int col;      // col where this piece goes

    public PuzzlePiece(Image i, int r, int c)
    {
        // Implementation not shown
    }

    // other instance variables and methods not shown
}

Of the following, which would be the BEST data representation for this puzzle in a Puzzle class?

A
public class Puzzle 
{
    private String[][] puzzle = new PuzzlePiece[20][30];

    // other instance variables and methods not shown
}
B
public class Puzzle 
{
    private PuzzlePiece[][] puzzle = new PuzzlePiece[21][31];

    // other instance variables and methods not shown
}
C
public class Puzzle 
{
    private PuzzlePiece[][] puzzle = new PuzzlePiece[22][32];

    // other instance variables and methods not shown
}
D
public class Puzzle 
{
    private PuzzlePiece[][] puzzle = new PuzzlePiece[23][32];

    // other instance variables and methods not shown
}
E
public class Puzzle 
{
    private String[][] puzzle = new String[22][31];

    // other instance variables and methods not shown
}
Select an assignment template