Part A. Provide an implementation RectangularGrid of the Grid interface (given in the netbrat code) that is based on a two-dimensional array.

Draft: The constructor, get, and set methods. Have the other methods return null.

netbrat draft | final

Part B. Provide an implementation UnboundedGrid of the Grid interface that models a grid where the rows and columns can be arbitrary integers. (The grid isn't actually unbounded at any time since it will only contain a finite number of nonzero elements.)

Hint: Store an array list of the locations with nonzero values, and a parallel array list of values. The order can be arbitrary. Use ArrayList.indexOf to find a location.

Draft: The constructor, get, and set methods. Have the other methods return null.

netbrat draft | final

Part C. Reimplement Homework 12B using a Grid (you don't know which kind) instead of a two-dimensional array.

Hint: locationsWithNeighbors is a bit tricky since the grid tells you only the nonzero locations. You have to iterate through them and their neighbors since an empty location that is adjacent to an occupied one can have a nonzero neighbor count. Make sure that each location occurs only once in the result.

Your method doesn't have to be efficient.

Draft: The countNonZeroNeighbors method

netbrat draft | final