Course Links

Exercises

Resources

External

This assignment will introduce you to the world of Java applications and graphics, in addition to giving you some practice building your own classes. You will create two classes that will work together (along with a third class written by me): class MapGrid will store map information in a 2D array, and class MapViewer will present various graphical views of that information. You will use the two classes to present two or more views of a world or scene you have created.

You are encouraged to work on this assignment with a partner, although students with strong reasons for wishing to work alone may petition me to do so. If you have not already seen it, I also encourage you to read “All I Really Need to Know about Pair Programming I Learned in Kindergarten,” containing helpful strategies for making pair programming work at its best. The original paper is by Laurie A. Williams and Robert R. Kessler, but you can read the shorter summary by Andrew Harrington instead.

Overview

This assignment is the first step towards an application you will write that is intended to work something like Google Maps. For this week you will write a program that sets up a map's contents (stored in a class called MapGrid) and then displays two different views of it, each in a separate window. The window display will be handled by a second class called MapViewer. The interaction between your classes should go something similar to the talk between the Surveyor and the Artist(s) in the skit performed in class. The Executive represents a third class largely written by me, which I provide to you below.

For this week you'll just be creating passive display windows, but in next week's assignment you will reuse the classes created here and add interactive controls that will allow the user to scan around the map and zoom in or out. You'll also be able to import maps from an image file of your choice.

Required Classes

The two classes you will write each have distinct purposes. Class MapGrid is a "data" class -- it keeps track of a grid of colors, and all its methods are either accessors or manipulators of some form. Class MapViewer, on the other hand, is an "action" class -- it will work with the data stored in some MapGrid, and display some portion of it in a graphics window. The remainder of this section gives some more specifics on each of the two classes.

map example

The MapGrid class will represent a map by storing a 2D array of Color values, each representing the contents of a particular grid square. For example, the image at right shows a 10x15 map representing a house surrounded by grass, a pool, a road and driveway. Note that MapGrid alone does not include any methods to display the spatial information it contains; that is the job of the MapViewer. The sole job of MapGrid is to organize and keep track of the data related to the map.

Class Color used within MapGrid is a predefined Java class; Sun publishes Javadoc information on all such standard Java classes on the web. You can generally find the Javadoc for a standard class Foo by Googling something like Java 8 class Foo. The documentation for class Color is here.

The MapViewer class is responsible for drawing a visible representation of a MapGrid on the screen. Note that there is not necessarily a one-to-one relationship of MapGrid to MapViewer: a particular MapGrid may not be displayed by any viewers, or it may be displayed by more than one. To emphasize this point, your program here will create two views of the same map. Furthermore, the number of viewers could potentially change over time in some future program.

The following links gives further details to help you plan the design of each class: MapGrid, MapViewer.

The Program

The classes described above are all very well and good, but to really see how they fit together you have to use them in a program. We will use a simple application program (class MapApplication) to test them out. Since you are already writing two other classes for this assignment, most of MapApplication is already given to you: skeleton MapApplication. You will have to fill in a few pieces; the parts you write should create an instance of MapGrid and put some features into it to make it look interesting. (You may use the map shown above as an example, but I'd rather see something you make yourself. Be creative.) You will also need to add lines to twice call the MapViewer constructor that you wrote, and possibly also call some manipulators to set the viewing parameters.

Remember that the two MapViewer instances should show different views! Each viewer window should have a different magnification and show a different visible area (although they may overlap). For example, the first view might show the whole map, at a small magnification, while the second map might show a closeup of one region of the map.

Reflections

Programming should be a reflective exercise, especially in this class where we learn new techniques every week. For the reflection, please consider the work just completed. What do you think was the most valuable part of the assignment? Do you feel you have mastered some new techniques, or at least gained a better understanding? Did you learn any better ways of doing something, or tricks that may be useful to others? Did the assignment shed light on something you had learned previously? Did the assignment frustrate you, and if so, how? The content of your reflections will not affect your grade, with the exception that particularly deep reflections may be considered for extra credit.

To Submit

Except when otherwise noted, please be sure that all files are named as described. Submit all files as assign2. If you work as a pair, just one partner should submit the program files, but each person should complete individual reflections (identifying her partner by name and account id).

Quick Start