Class Program5


  • public class Program5
    extends Object
    Question 5. 2D Arrays [23 marks]
    • Constructor Detail

      • Program5

        public Program5()
    • 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)