Question: [Java] Use graphic2D please. and Don't scribble the code. For this problem you will create a crude temperature map. A TemperatureMap class indicates areas of
[Java] Use graphic2D please. and Don't scribble the code.
For this problem you will create a crude temperature map. A TemperatureMap class indicates areas of different temperature by the use of different colors. Our map will represent a square area. The temperatures are contained in a 2d int array. Each element in the array represents the temperature in a square area 20 miles on a side. We assume the temperature is the same through-out the area.
The constructor takes a 2d array of ints as a parameter
Provide these methods:
public void drawMap() creates a map consisting of colored squares. Each square represents the temperature indicated by an element in the array. There is a one-to-one correspondence between the array elements and the squares on the map. The upper left hand corner of the map is at (0, 0). The squares are 10 px X 10 px. Draw the rows and then the columns
The color of the square is determined as follows:
Color.BLUE if the temperature is less than or equal 32
Color.GREEN if the temperature is greater than to 32 and less than or equal to 50
Color.ORANGE if the temperature is greater 50 but less than or equal to 85
Color.RED if the temperature is greater than 85
Write a private helper method to get the color.
public int maxDifference() gets the difference between the highest and lowest points in the map as a positive number.
The map will look like this
Use the following files:
TemperatureMapComponent.java
import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.util.Random; import javax.swing.JComponent; public class TemperatureMapComponent extends JComponent { private static final long serialVersionUID = 1L; public void paintComponent(Graphics g) { // Recover Graphics2D Graphics2D g2 = (Graphics2D) g; final int DIMENSION = 20; final int MAX_TEMPERATURE = 105; final int MIN_TEMPERATURE = -10; int[][] mapData = new int[DIMENSION][DIMENSION]; Random gen = new Random(987654321); for (int row = 0; row TemperatureMapViewer.java
import javax.swing.*; /** * Displays a TemperatureMap */ public class TemperatureMapViewer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 400); frame.setTitle("Teperature Map"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TemperatureMapComponent component = new TemperatureMapComponent(); frame.add(component); frame.setVisible(true); } } Teperature Map Difference: 114 Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
