CSC 212: Programming with Data Structures

Homework 2: Viewing Maps

Due: Wednesday, Feb. 10, 11:59pm

Credit for this assignment: Nick Howe


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: a MapGrid class that will store map information in a 2D array, and a MapViewer class that can 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.

For this assignment we will be using pair programming, although if you have a strong reason for wanting to work alone, you may petition me to do so. If you don't know many people in the class, email me and I will set up partners. I would ideally like students from the same year to work together, since they often have similar experience levels. Make sure to switch frequently and communicate the entire time about what is happening with the code.

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.

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.


Required Classes

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. 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.

demo

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 above 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 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 once. 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 (MapApplication) to test them out. Since you are already writing two other classes for this assignment, most of MapApplication is already given to you:

MapApplication.java

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?

How was your experience with pair programming? What were the positive aspects of this process? What were the negative aspects?


To Submit

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

  • readme.txt, containing your reflections (to be completed individually)

  • MapGrid.java

  • MapViewer.java

  • MapApplication.java

  • typescript showing a clean compile only

  • screenshot.png, a screenshot showing your output