Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;

image text in transcribedimage text in transcribed

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 listOfHouses = new ArrayList(); double[][] elevationLevels = { {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, }; JFrame frame = new JFrame(); frame.setSize(900,900); frame.setTitle("Higher Ground!"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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 listOfHouses; private double waterLevel;

/** * A constructor. * * (You can add more constructors if you wish.) * @param homes * @param levels */ public Map(ArrayList homes, double[][] levels) { cellArray = getGrid(); listOfHouses = homes; elevationLevels = levels; }

/** * 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: ArrayList Use a while loop (or a do-while loop) to enable the user to enter coordinates for as many houses as they want. Use a sentinel value (like a negative coordinate) to terminate the loop. Your code must be responsive to changes: if I change the elevation map, the list of houses, or the water level, the map should be update accordingly. Your code will be well-commented and well-organized. . Don't worry about . Filtering user input (e.g., making sure they don't punch in 5.2 or "help" for a coordinate) The exact nature of how you draw your houses. If you're an artist, great! If not, great! Do worry about: Zombies (for obvious reasons) Not a requirement, but... Have fun with this! Be creative with the graphics, print out funny messages, or maybe even add some other stuff to it. Hints: I recommend using Project7Starter Pack.zip on Moodle to get you going. You'll need to familiarize yourself with a few new classes (Color, Line 2D, etc.). Check out which classes l imported in Project7Starter Pack, and look them up in the Java API. The last several sections of Chapter 2 in our book help quite a bit when learning the ropes of drawing things on a JComponent. 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: ArrayList Use a while loop (or a do-while loop) to enable the user to enter coordinates for as many houses as they want. Use a sentinel value (like a negative coordinate) to terminate the loop. Your code must be responsive to changes: if I change the elevation map, the list of houses, or the water level, the map should be update accordingly. Your code will be well-commented and well-organized. . Don't worry about . Filtering user input (e.g., making sure they don't punch in 5.2 or "help" for a coordinate) The exact nature of how you draw your houses. If you're an artist, great! If not, great! Do worry about: Zombies (for obvious reasons) Not a requirement, but... Have fun with this! Be creative with the graphics, print out funny messages, or maybe even add some other stuff to it. Hints: I recommend using Project7Starter Pack.zip on Moodle to get you going. You'll need to familiarize yourself with a few new classes (Color, Line 2D, etc.). Check out which classes l imported in Project7Starter Pack, and look them up in the Java API. The last several sections of Chapter 2 in our book help quite a bit when learning the ropes of drawing things on a JComponent

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

=+2. Which of the following best describes negative reinforcement?

Answered: 1 week ago

Question

a valuing of personal and psychological privacy;

Answered: 1 week ago