Question
MAPTESTER package project7starterpackv3; import javax.swing.JFrame; import java.util.ArrayList; public class MapTester { public static final int NUMBER_OF_ROWS = 10; public static final int NUMBER_OF_COLUMNS = 10;
MAPTESTER package project7starterpackv3;
import javax.swing.JFrame; import java.util.ArrayList;
public class MapTester { public static final int NUMBER_OF_ROWS = 10; public static final int NUMBER_OF_COLUMNS = 10; public static void main( String[] args ) { ArrayList
Map component = new Map(listOfHouses,elevationLevels); component.setWaterLevel(5); frame.add(component);
frame.setVisible(true);
} }
MAP
package project7starterpackv3;
import java.awt.Color; import java.awt.geom.Line2D; import java.awt.geom.Ellipse2D; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.BasicStroke; import java.util.ArrayList;
import javax.swing.JComponent;
public class Map extends JComponent { /** * This aids draws color-coded maps. */ private static final long serialVersionUID = 1L; public static final Color LIGHT_BLUE = new Color(0, 200, 220); public static final int NUMBER_OF_ROWS = 10; public static final int NUMBER_OF_COLUMNS = 10; public static final int startX = 25; public static final int startY = 25; public static final int cellSize = 60;// for height and width of individual rectangles public static final int SMALL_NUMBER_OF_PIXELS = 6;
private final double[][] elevationLevels; private final Rectangle[][] cellArray; private final ArrayList
/** * A constructor. * * (You can add more constructors if you wish.) * @param homes * @param levels */ public Map(ArrayList
/** * Sets the water level and re-draws the map. * * You probably should just use this method and not change it. * @param level */
public void setWaterLevel(double level) { waterLevel = level; repaint();//the repaint method calls the paintComponent method (see below) //I use repaint when I need to update what is displayed on the screen when //I know that some instance variables have changed. }
/** * Used to initialize a 2-d array of Rectangles, which can then in turn be used * as references from which to draw things on the map. * * My guess is that you're not going to want to mess with this method. */
private static Rectangle[][] getGrid() { Rectangle[][] grid = new Rectangle[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS]; int currentX = startX; int currentY = startY;
for (int ii = 0; ii
return grid; }
/** * This does the actual drawing. * In "starter pack mode", this just has some sample drawings * that hopefully will give you some ideas as to how you can * do things. * @param g */
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g;
for (int ii = 0; ii
} } } } }
HOUSE
package project7starterpackv3;
public class House { private final int[] location = new int[2];// the [0] position is the row number, the [1] position is the column number
public House(int row, int column) { location[0] = row; location[1] = column; }
public int[] getLocation() { return location; } }
Programming Assignment #7: Higher Ground Your task/Functional Requirements: Write a program that uses a 10-by-10 array of doubles that gives the height of a terrain at different points in a grid to draw a map of the terrain. Higher elevations should be colored darker than lower elevations, and all places in the terrain below a specified water level ought to be colored blue. See the screenshot below: . Once your program displays the map, it will prompt the user to enter coordinates of where to put houses on the map. Once the user is done entering in these coordinates, your program should re-draw the map with the houses in the appropriate locations and indicate visually whether each house is underwater. Below is an example with houses at (1,3), (1,2), (8,6), and (4,7): . Methodological Requirements: The array of elevations must be declared as follows: double(10) elevationLevels = ...; You can choose the numbers to place into it, just make sure that it makes a reasonably interesting map i.e., not all squares have the same elevation, you're not using my default checkboard pattern, etc.). You will use the House class provided in Project7Starter Pack. You may add methods, instance variables, new constructors, etc., but you must use this class. Store the list of houses (as objects of the House class) input by the user in an array list (*not* an array). Hint: ArrayListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started