SA-1
This assignment is based on a true story. Commercial fisherman John Alderidge fell overboard from a moving boat miles from shore and his crew mates did not notice his absence until hours later. The Coast Guard initiated a search immediately after learning about the incident, but the odds of finding John were small — he was a small speck in large ocean. In this assignment you will help the Coast Guard optimize the search.
While no one knew exactly when John went overboard, the Coast Guard did know the boat’s course and could estimate how John would drift in the ocean currents. This meant John was more likely to be in some parts of the ocean than others. The Coast Guard created a virtual grid over the ocean and estimated the probability John would be in any particular (row, col) grid square. The diagram below shows an example of a 13 row by 6 column grid where darker colors indicate locations more likely to contain John, lighter colors represent locations less likely to contain John. The Coast Guard wants to send helicopters to search the most likely locations first.

Exercises
- Create a
SearchAndRescue
class that uses a two-dimensional array to represent anm
row byn
column grid. Your constructor should takem
andn
as parameters and store them in addition to creating and storing the grid array. Each grid location holds the Coast Guard’s estimate of the probability (a number between 0 and 1) that John is in that particular square. Initialize each grid square to 1/total number of grid squares (e.g., each grid square is initially equally likely to contain John). - Complete the following method for your
SearchAndRescue
class that allows the Coast Guard to update their estimate of the probability John is located in a (row, col) grid location. Assume the Coast Guard will initially call this method many times to set their initial estimate of where John is likely located. Print an error message if row or col are invalid. Also print an error message if the probability is invalid.public void setGridProbability(int row, int col, double probability) {
- Write a method for your
SearchAndRescue
class calledbestLocation
that prints the (x,y) location most likely to contain John so the Coast Guard can vector helicopters to search for him there. If multiple locations tie for the highest probability, choose one of them however you see fit.
I recommend begining this class from scratch, but you may use SearchAndRescue.java as a starter if you'd like. (NOTE: the scaffold contains a main
method with some test cases and a toString
method for printing the grid.)
Submission Instructions
Turn in your completed SearchAndRescue
class's .java file. Provide a main
method with several test cases to show your code works as expected.