Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. A crossword puzzle grid is a two-dimensional rectangular array of black and white squares. Some of the white squares are labeled with a positive

image text in transcribedimage text in transcribedimage text in transcribed

3. A crossword puzzle grid is a two-dimensional rectangular array of black and white squares. Some of the white squares are labeled with a positive number according to the crossword labeling rule. The crossword labeling rule identifies squares to be labeled with a positive number as follows. A square is labeled with a positive number if and only if - the square is white and - the square does not have a white square immediately above it, or it does not have a white square immediately to its left, or both. The squares identified by these criteria are labeled with consecutive numbers in row-major order, starting at 1. The following diagram shows a crossword puzzle grid and the labeling of the squares according to the crossword labeling rule. This question uses two classes, a Square class that represents an individual square in the puzzle and a Crossword class that represents a crossword puzzle grid. A partial declaration of the Square class is shown below. A partial declaration of the Crossword class is shown below. You will implement one method and the constructor in the Crossword class. public class Crossword /** Each element is a Square object with a color (black or white) and a number. * puzzle [r][c] represents the square in row r, column c. * There is at least one row in the puzzle. */ private Square[][] puzzle; / Constructs a crossword puzzle grid. * Precondition: There is at least one row in blackSquares. * Postcondition: * - The crossword puzzle grid has the same dimensions as blacksquares. * - The Square object at row r, column c in the crossword puzzle grid is black * if and only if blackSquares [r][c] is true. * - The squares in the puzzle are labeled according to the crossword labeling rule. / public Crossword(boolean [] [] blacksquares) {/ to be implemented in part (b) /} J Returns true if the square at row r, column c should be labeled with a positive number; * false otherwise. * The square at row r, column c is black if and only if blackSquares [r][c] is true. * Precondition: r and c are valid indexes in blackSquares. */ private boolean toBeLabeled(int r, int c, boolean[][] blackSquares) {/ to be implemented in part (a) /} // There may be instance variables, constructors, and methods that are not shown. 3 (a) Write the Crossword method toBeLabeled. The method returns true if the square indexed by row r, column c in a crossword puzzle grid should be labeled with a positive number according to the crossword labeling rule; otherwise it returns false. The parameter blackSquares indicates which squares in the crossword puzzle grid are black. Complete method toBeLabeled below. / Returns true if the square at row r, column c should be labeled with a positive number; * false otherwise. * The square at row r, column c is black if and only if blacksquares [r] [c] is true. * Precondition: r and c are valid indexes in blacksquares. / private boolean tobeLabeled(int r, int c, boolean[][] blackSquares) (b) Write the Crossword constructor. The constructor should initialize the crossword puzzle grid to have the same dimensions as the parameter blacksquares. Each element of the puzzle grid should be initialized with a reference to a Square object with the appropriate color and number. The number is positive if the square is labeled and 0 if the square is not labeled. Assume that toBeLabeled works as specified, regardless of what you wrote in part (a). You must use toBeLabeled appropriately to receive full credit. Complete the Crossword constructor below. / Constructs a crossword puzzle grid. * Precondition: There is at least one row in blackSquares. * Postcondition: * - The crossword puzzle grid has the same dimensions as blacksquares. * - The Square object at row r, column c in the crossword puzzle grid is black * if and only if blacksquares [r][c] is true. * - The squares in the puzzle are labeled according to the crossword labeling rule. / public Crossword(boolean [] [] blacksquares)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Google Analytics 4 The Data Driven Marketing Revolution

Authors: Galen Poll

2024th Edition

B0CRK92F5F, 979-8873956234

More Books

Students also viewed these Databases questions

Question

1. Describe a dialectical approach to cultural transitions.

Answered: 1 week ago