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.

netbrat draft | final

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

Draft: countNonZeroLocations

netbrat draft | final

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 arraya andb. The number of columns in the results array will be the larger of the number of columns in arraysa and b

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

Here are the images that are used in PictureViewer. 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.

netbrat draft | final