Class Program5
- java.lang.Object
-
- Program5
-
public class Program5 extends Object
Question 5. 2D Arrays [23 marks]
-
-
Constructor Summary
Constructors Constructor Description Program5()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkRowsContinuous()
(b) [15 marks] Complete the checkRowsContinuous() method so that it counts the number of *continuous* filled squares in each row, and checks that the count matches the value stored in rowCounts for that row.boolean
checkRowsSimple()
(a) [8 marks] Complete the checkRowCountsSimple() method so that it counts the number of filled squares in each row, and checks that the count matches the value stored in rowCounts for that row.void
doCheckRowsContinuous()
Run checkRowsContinuous() and output the result.void
doCheckRowsSimple()
Run checkRowsSimple() and output the result.void
drawGrid()
Draws the grid on the screen.static void
main(String[] args)
void
makeNewGrid()
Creates a new random grid.void
setupGUI()
-
-
-
Field Detail
-
TOP
public final int TOP
- See Also:
- Constant Field Values
-
LEFT
public final int LEFT
- See Also:
- Constant Field Values
-
SIZE
public final int SIZE
- See Also:
- Constant Field Values
-
GRID_LEFT
public final int GRID_LEFT
- See Also:
- Constant Field Values
-
GRID_TOP
public final int GRID_TOP
- See Also:
- Constant Field Values
-
-
Method Detail
-
checkRowsSimple
public boolean checkRowsSimple()
(a) [8 marks] Complete the checkRowCountsSimple() method so that it counts the number of filled squares in each row, and checks that the count matches the value stored in rowCounts for that row. - Filled squares do not need to be next to each other. If the count for a row is 3, all of the following are valid: [X][X][X][ ][ ] or [X][X][ ][X][ ] or [X][ ][X][ ][X] - Your method should still work whatever the size of the grid array, assuming that every row of the array contains at least one column.- Returns:
- true if all the rows are valid, false otherwise
-
checkRowsContinuous
public boolean checkRowsContinuous()
(b) [15 marks] Complete the checkRowsContinuous() method so that it counts the number of *continuous* filled squares in each row, and checks that the count matches the value stored in rowCounts for that row. - Filled squares must be next to each other. If the count for a row is 3, all of the following are valid: [X][X][X][ ][ ] or [ ][X][X][X][ ] or [ ][ ][X][X][X] The following are all INVALID as the squares aren't next to each other [X][X][X][ ][ ] or [X][X][ ][X][ ] or [X][ ][X][ ][X] - Your method should still work whatever the size of the grid array, assuming that every row of the array contains at least one column.- Returns:
- true if all the rows are valid, false otherwise
-
makeNewGrid
public void makeNewGrid()
Creates a new random grid. The grid will be 4-6 squares in size, and the row counts will be random (but will always fit in the grid).
-
drawGrid
public void drawGrid()
Draws the grid on the screen.
-
doCheckRowsSimple
public void doCheckRowsSimple()
Run checkRowsSimple() and output the result.
-
doCheckRowsContinuous
public void doCheckRowsContinuous()
Run checkRowsContinuous() and output the result.
-
setupGUI
public void setupGUI()
-
main
public static void main(String[] args)
-
-