← All free-response questionsQuestion 4 · 2D Array · 6 points
Heat Map
A weather service stores temperature readings for a region in a 2D array. Each cell is one square of the map.
public class HeatMap
{
/** The temperature readings; rectangular, at least 1 x 1 */
private double[][] temps;
/** Returns the number of hot spots in temps, as described
* below.
*/
public int countHotSpots()
{ /* to be implemented */ }
// There may be instance variables, constructors,
// and methods that are not shown.
}Your class
6 pointsWrite countHotSpots. A cell is a hot spot if its temperature is strictly greater than the temperature of each of its neighbors directly above, below, left, and right. Neighbors that would be outside the array are ignored, so a cell on an edge has fewer neighbors.
| col 0 | col 1 | col 2 | col 3 | |
|---|---|---|---|---|
| row 0 | 71 | 68 | 70 | 75 |
| row 1 | 65 | 72 | 69 | 74 |
| row 2 | 80 | 70 | 73 | 60 |
The hot spots are in bold, so countHotSpots() returns 5. For example, 72 is greater than 68, 70, 65, and 69. The 74 is not a hot spot because 75 is above it.
Tab inserts spaces. Drafts save as you type.
Self-score
0 / 6