CSE143

Autumn 2002

Project 3 Warm Up

"Political Consultant"

Map files for testing

Some snapshots. Offsite (not part of 143 website): more snapshots by Chris Ross.

starter code directory  

Overall scenario: As a result of the recent census,  legislative districts everywhere have to be redrawn.  Impressed with your achievements as a computer-based historian, an international consulting firm has hired you to help their clients (local and regional governments) with a variety of mapping and political analysis problems.

As a first assignment, you've been given a file describing the outline of a state.  Draw the map.  Clients will view it to decide if they want you on their project.

Electronic deadline: The Warm Up will be due on Election Day, Tuesday, November 5, 2002.  Polls close at 9:00 p.m.  Paperwork can be handed in on Thursday, November 7.

You can use what you learned about files and Readers and string parsing in this project.  You will also have a chance to try some Swing drawing.  Behind all of it are general Java facilities such as inheritance and exceptions.


Functional summary description of the finished program: A user starts the program, and has an opportunity to specify (via the command line) a text file with data representing a map of the state.  If the file does not exist, or the user doesn't supply a file, the program should request and use an automatically created stream (this way the client can still assess your programming skill and style).   Assuming the data is in the proper format, the program then draws the boundaries of the state.  The map should also be "signed" with your name and section.  To really impress the client, fill in the interior of the shape with a solid color different from the background.  No extra credit, though :(

What You Have to Start With

You will have .class and .java files in the code directory (link above).  These make up a complete, runnable program.  The program does not, however, read in and display a map from a file.  It just displays a panel with a simple message.  The very first thing you should do is get this program running, as is.  If you can't get it to work on our own system because of Bluej or other problems, please come into the IPL to work.

The main class for the starter program is called MapMaker.java.

You will have source for a starter version of the MapPanel class.  Override the paintComponent method to display the map.  Warm up for this by doing some experimental drawing in that method -- maybe your name, some lines or shapes, etc.

You will have the code for MapReaderFactory.   The source is provided only as a reference --don't change it.   This class has static methods which create for you BufferedReaders for map streams ("files").  The readers will already be open and ready to go.  You can pass in a file name, or you can request a random file to be generated.  You can say how many edges the random file should have, or let the factory decide.  This will be your easiest way of testing!  The random files you get will never be two alike.  They are streams created on the fly; you can't save them to disk, and you can only read through them once.  There will be other .class files that will not be documented but that are needed at run-time to support the various starter and sample files.

Somewhere in your program you will need to read all the lines of BufferedReader, interpret them as points and lines, and save the information for paintComponent to use.

You are free to modify MapMaker.java.  It must be to be turned in.  When its main method is started, it should execute your entire program.  Note that code for taking a file name argument from the command line is already in the driver class.

You are free to create additional .java files, too, as long as your MapMaker main operates as described to run the program.

You are free to change the drawGUI.java file.  [Hint: you almost certainly have!]

File Format

To make the map, the state's boundaries are "quantized" to line segments.  That is, the map has no curves.  Instead, there is a number of line segments which approximate the boundary.  This number may vary from file to file.

Each line of the file represents one boundary segment.  The same segment will not be in the file more than once.  In the line of the file, there are four double numbers, separated by one or more spaces.  The first two numbers are the x,y coordinates of one end of the segment, and the last two numbers are the x,y coordinates of the other end of the segment.  For example, the line

       10.1  200  400  82.5

represents the segment from (10.1, 200) to (400, 82.5) on the screen.  (Programming note: some AWT and Swing methods allow you to use doubles as screen coordinates; other methods require integers.  Java will silently convert ints to doubles, but not vice-versa.)

There is no particular order to the segments on the file.  That is, segments which are adjacent in the map might not be adjacent in the file.

Valid maps (for this part of the project) are closed polygons, with no lines that cross, and no lines that are drawn off the screen.  For the warm-up, at least, you can assume that the randomly generated maps will all be valid polygons.

Errors in the file of any sort should be detected and reported; the program does not have to attempt recovery.  As usual, an unexpected user or file error should not cause the program to terminate unknowingly.

Internal Requirements

There are some requirements that your programming must meet, or the program may not even be gradable.

The big (and weird) one: NO ARRAYS ALLOWED! Arrays are great, but it's important to practice with other structures, too.

If your program uses a collection that has an iterator, you should use the iterator instead of a counting loop, if at all possible.

Test Files and Other Testing Requirements (and Opportunities!)

Label the printouts with the name of the file, as well as your name, section, and date as usual.

Service Opportunity

Prepare a test file of an actual state of the US (something more complicated that Colorado, please!) or of a foreign country.  As with previous project, include // comments identifying yourself, the source of the data, and the method of preparation.  This opportunity will remain open past the Warm Up phase.

Analytical Exercise

Either none, or to be supplied, with its own instructions and due date.

Notes on Style and Practice

Now you have seen an authentic style guide and used it to critique a program.  This time, we ask you to use Sun's Code Conventions for Java Programmers to guide your own programming practice.

A Few More Notes

For the first part of the project, the work should be done by individuals rather than in teams.

You are free to use any standard Java library class or method. You shouldn't use code from outside the course, but if you do, recognize that with a comment in the code.

Keep the AWT/Swing part of it simple.  See the lecture slides (toward the end) for a suggested list of classes and methods; you probably won't have to go far beyond this.

Looking Ahead

As noted early in this page, it would be especially impressive if you could fill in the polygon with a solid color.  This will be required in the next stage of the project.  It is surprisingly more difficult than just drawing the outline.   Get the outline working first.  There's no extra credit for getting the fill to work this time -- it would just put you ahead for the next stage.

More looking ahead: the program will eventually have to be able to handle // comments at the beginning of the file.  You may include that capability now if you wish.

Good Luck and Have Fun!

Click here to submit electronically.