In a paint program, a “flood fill” fills all empty pixels of a drawing with a given color, stopping when it reaches occupied pixels. In this exercise, you will implement a simple variation of this algorithm, flood-filling a 10 × 10 array of integers that are initially 0. Prompt for the starting row and column. Push the (row, column) pair on a stack. (You will need to provide a simple Pair class.)

Then repeat the following operations until the stack is empty.

When you are done, print the entire array.

Complete the following files:

FloodFillTester2.java

Grid.java

public class Grid { private static final int SIZE = 10; int[][] pixels = new int[SIZE][SIZE]; . . . /** Flood fill, starting with the given row and column. */ public void floodfill(int row, int column) { . . . } public String toString() { String r = ""; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) r = r + String.format("%3d", pixels[i][j]); r = r + "\n"; } return r; } }

Pair.java

Use the following files:

FloodFillDemo.java

public class FloodFillDemo 
{
   public static void main(String[] args)
   {
      Grid gr = new Grid();
      gr.floodfill(3, 4);
      System.out.println(gr.toString());
   }
}

FloodFillTester.java

public class FloodFillTester
{
   public static void main(String[] args)
   {
      Grid gr = new Grid();
      gr.floodfill(3, 4);
      String[] rows = gr.toString().split("\n");
      System.out.println(rows[2]);
      System.out.println("Expected: 15 12  9  6  2 81 79 77 75 73");
      System.out.println(rows[3]);
      System.out.println("Expected: 14 11  8  5  1  3 78 76 74 72");
      System.out.println(rows[4]);
      System.out.println("Expected: 16 13 10  7  4 63 65 67 69 71");
   }
}