Extra Credit Program: Recursion, Find Groups
This is problem 7.31 from the textbook. Use Cartesian coordinates (column, row) to refer to squares: (0,0) is the lower, left-hand corner of the board, (2,1) would be two squares to the left and one up from that.
The FindGroup class must provide these methods:
- public FindGroup(boolean[][] board) Constructor to initialize to a given board. The board is guaranteed to be rectangular. A value of true indicates that the corresponding square is occupied.
- public int sizeGroup(int col, int row); Return the size of the group containing the given square. If square is not occupied, return 0.
- public int numGroups( ) Return the number of groups in the board. Could be 0.
- public void printGroups() Print all groups in the boards. Make sure no square appears in more than one group. Output should be of the form shown below:
Group 1: {(9,9), (9,8)}
Group 2: {(3,8), (4,8)}
etc.
List the groups that appear from top to bottom. If more than one group's topmost element appears in the same row, print the groups from left to right.