Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public String toString ( ) Returns a String representing the characters stored in grid in a format that is easy to read, that exactly matches
public String toString
Returns a String representing the characters stored in grid in a format that is
easy to read, that exactly matches the format given below.
o new LetterCrush"AACADBBDCD"toString must return
Note the row number at the end of the to lines, and the column numbers in
the last row. The column indices will always be onedigit values grids with widths
greater than nine will not be tested
public boolean isStable
Returns false if there is any position in grid where a nonEMPTY character is
above an EMPTY character a grid entry with a smaller row than a grid entry with
a larger row in the same column thus, for the example given above in the
description of the toString method, isStable would return false
Otherwise, returns true.public Line longestLine
O Returns null if there does not exist in grid a line of at least adjacent matching letters.
Otherwise, returns a uniquely defined longest line in grid that contains adjacent
matching letters. To make this method unambiguous, preferences must be
specified to select among equally long lines of adjacent matching letters. Use
these preferences for this method:
A horizontal line has preference over a vertical one of the same length.
If two horizontal lines have the longest length, then we give preference to
the line appearing in the lowest row largest index; if both lines are in the
same row, we prefer the line that appears to the left.
If two vertical lines have the longest length, we give preference to the line
that appears in the leftmost column; if both lines appear in the same
column, we prefer the line the appears at the bottom.
For example, if there are three lines with the maximum length and none of them
are horizontal, and among these lines two of them are in the same column but to
the left of the third line, then the line in the left column that appears in the lowest
row will be the one that is returned.
See the pseudocode below for details.public void cascade
O This method iteratively removes the longest line of adjacent matching letters, of
length at least and repeatedly invokes the applyGravity method to shift letters
from grid to the empty spaces until no more shifts are possible you can check
this by invoking method isStable The process is repeated until the longest line
of adjacent matching letters has a length less than three.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started