- Be sure to read the "Individual Work" section of your green sheet. You
may not copy your work from another student. You may not collaborate with
other students, except on Piazza. When code is posted on Piazza, it is
usually far from perfect and should not be copied without improving it. If
you do copy from Piazza, you MUST provide attribution. Use the format
// https://piazza.com/class#fall2012/cs46a/911

Part A. A rectangular terrain { (x, y) | xmin ≤ x < xmax and ymin ≤ y < ymax } is subdivided into rows and columns of smaller rectangles, each of the same size dx • dy, where dx = (xmax - xmin) / columns and dy = (ymax - ymin) / rows.

The rectangle in row r and column c is { (x, y) | xmin + c • dx ≤ x < xmin + (c + 1)• dx and ymin + r • dy ≤ y < ymin + (c + 1)• dy }

A *terrain map* stores the heights of these rectangles.

Write a constructor

public TerrainMap(double xmin, double xmax, double ymin, double ymax, int rows, int columns, double defaultHeight)

methods

public void set(double x, double y, double height) public double get(double x, double y)

and a method

public void printTerrainMap(double waterLevel)

that prints out a flood map, showing which of the rectangles in the terrain would be flooded if the water level was the given value. In the flood map, print a * for each flooded point and a space for each point that is not flooded.

Draft: The constructor and get method.

Part B. Write the following methods in a class `Grids`

:

`public static int countNonZeroNeighbors(int[][] grid, int row, int column)`

`public static ArrayList<Location> locationsWithNeighbors(int[][] grid, int neighborCount)`

`public static void setLocations(int[][] grid, ArrayList<Location> locations, int value)`

Draft: `countNonZeroLocations`

Part C. We want to take two pictures, convert them to black-and-white, overlay them, and display the composite picture.

A picture is represented by a two dimensional array. The elements in the
array indicate the amount of gray at each pixel. The value can vary from 0 to
255. The class `Picture`

has been provided for you as well as a
`PictureViewer`

so you can see the application visually. There is
some advanced code in these classes that you do not need to worry about.

Your job is to write a class `Pictures`

that has a static
`merge`

method which `PictureViewer`

will use to merge
the two images. There is a `MergeTester`

class provided to help you
test the method.

The signature for the merge method is:

public static int[][] merge(int[][] a, int[][] b)

The parameter arrays *a* and *b* may be different sizes. Look
in your text to find out how to calculate the size of each dimension in a 2D
array. The number of rows in the results array will be the larger of the number
of rows in array*a* and*b*. The number of columns in the results
array will be the larger of the number of columns in arrays*a* and
*b*

The value of an element at a given position in the results array is calculated as follows:

- If the position exists in both arrays, the value in the results array is
the
**average**of the values in array*a*and*b*. - if the position exists only in array
*a*, the value in the results array is the value in array*a* - if the position exists only in array
*b*, the value in the results array is value in array*b* - if the position is in neither array assign a value of 127 at that position in the results array.

Here are the images that are used in `PictureViewe`

r. You will
need to copy them into the folder that holds your Bluej project along with
`PictureViewer.java`

and `Picture.java`

in order to run
`PictureViewer`

and see your method in action.

Draft: Make `merge`

work for two arrays, each of which has size
2 x 5.