For this assignment, you are to create a program in Java that counts the number of holes in an rectangular grid array. The grid array will contain integers with values of either zero (space) or one (solid block). A space is connected to another space if it is above, below, to the right, or left of the other space. A hole is a connected set of spaces. You can assume that holes are simple (i.e. no holes inside holes), do not touch the edges of the grid, and do not share corners with other holes. Your program should output the number of holes in an array grid that is loaded from a file. Here is an example of a grid array with four holes:
1111111111
1001110011
1011111111
1110000011
1110000011
1111110011
1111011011
1111111111
Here are examples of grid arrays that CANNOT occur:
1111111111
1001110011
1001111111
1110000011
1110000011
1111110011
1111011011
1111111111
This one has two holes that share a corner (in top-left).
111111111
000111001
000111111
111000001
111000001
This one has holes that touch the edges of the grid.
1111111111
1000000011
1001110011
1001010011
1001110011
1000000011
1111000011
1111111111
This one has non-simple holes (a hole within a hole).
The program shall work as follows:
1. Load the "grid.txt" file, which contains the grid array. The first line of this file contains the dimensions of the grid, which are two comma-separated integers (rows,columns). The rest of the file contains the values of the data array (0 or 1), without any separation. Here is an example:
8 10
1111111111
1001110011
1011111111
1110000011
1110000011
1111110011
1111011011
1111111111
2. Count the number of holes in the grid array. Display this to the screen as shown in the sample output.
Your code needs to be decomposed into separate (static) methods that do particular tasks. Your main method should use these methods to implement the whole program.
1. The name of your Java Class that contains the main method should be HoleCounter. All your code should be within the same file.
2. Your code should follow good coding practices, including good use of whitespace (indents and line breaks) and use of both inline and block comments.
3. You need to use meaningful identifier names that conform to standard Java naming conventions.
4. The output of your program should exactly match the sample program output given at the end.
HINT - one way to count the holes is to go through each array element, and if it is an empty space, "flood" it with a unique number, which afterwards, gets incremented.
Programming Fundamentals
NAME: < name >
PROGRAMMING ASSIGNMENT 3
1111111111
1001110011
1011111111
1110000011
1110000011
1111110011
1111011011
1111111111
Number of holes is 4