Introduction

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).

Requirements

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.

Program Design Requirements

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.

Additional Requirements

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.

Sample Program Output

Programming Fundamentals
NAME: < name >
PROGRAMMING ASSIGNMENT 3

1111111111
1001110011
1011111111
1110000011
1110000011
1111110011
1111011011
1111111111

Number of holes is 4
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.