CS 201 - Computer Science I - Spring 2003
Project 1 - Using objects


Loyola College > Department of Computer Science > CS 201 > Projects > Project 1

Due

Tuesday, February 25th Wednesday, February 26th Thursday, February 27th at 11:59pm. Late projects will be assessed a 20% penalty for each day past the due date. Projects will not be accepted more than four days past the due date.

Objectives

Introduction

The applet for this project allows the user create a map showing the locations of any street addresses entered. To add a location to the map, the user must type the address in the input field at the top of the applet and click the "Add" button. The "Clear" button clears all entered locations off the map.

In the example given below, legal house numbers are from 1 to 999 with 1 being on the left of the screen and 999 being on the right. Street names are, from south to north, "Amherst", "Benokraitis", "Clocktower", "Denver", "Eastman", "Foxboro", "Glenn", "Halfling", "Iverson", "James", "Karen", "Lafayette", "Midway", "Northern", "Ohio", "Pennsylvania", "Quiet Ways", "Reeds Landing", "Sea Shadow", "Terrapin", "Ugly Spring", "Vilnius", "Whitetail", "Xanadu", "Yocco", and "Zayre". Entering "500 Northern Parkway" would then put an icon in the middle of the map.

This applet will not run under Internet Explorer (it will run under most current versions of other browsers). To run it on a lab machine, open a Command Prompt window with the Start menu, and type

cd \jdk1.3\bin
and then
appletviewer http://gunpowder.cs.loyola.edu/~jglenn/201/S2003/Projects/P1/proj1.html
(you can copy the URL from the browser and paste it into the Command Prompt window).

Assignment

Most of the applet has been written as three classes: MapApplet which, as the applet class, sets up the user interface components, Geocoder, which translates from street addresses to longitude and latitude, and HouseView, which is a custom component that draws the map that makes up the bulk of the applet's window.

A few of the methods needed for the applet have been omitted; you must write these in a new class called Project1. Your code will have to interact with the classes described above as well as with classes from the Java libraries including Graphics, Point2D, and String.

The three methods you must write are

Note that all three methods are static and so when you write them you they should start public static void.

The supplied classes include the following methods and constructors that will be useful to your code.

The supplied classes have more complete documentation (get used to seeing things like this). Documentation for the Java library classes used in this project is, of course, included in the Java API documentation.

Suggestions

Start by creating an applet that draws a house. Modify the code from the paint method of that applet to create your drawHouseIcon method in the Project1 class.

To test the resulting method with the applet, create an empty clearMap method and put only the following line in your addHouse method

  view.plotHouse(new Point2D.Double(-77.05, 39.05));
When you run the applet and click "Add", you should see a small house in the middle of the screen. By changing the two numbers (keep the first between 39.0 and 39.1 and the second between -77.0 and -77.1) you should be able to move the house around the screen.

Next work on reading the address from the TextField and splitting it into a house number and street name. You can use System.out.println to see the result of your efforts.

When you have the address split properly, use the Geocoder class to convert to coordinates. Pass the coordinates to plotHouse and you should be able to enter addresses and see them drawn on the map.

Finally, complete your clearMap method.

Files

Save all three files to the same directory (right-click on the link and choose "Save Link As"). Create your Project1.java file in that same directory. To run the applet, open the MapApplet.java window and choose "Compile" and then "Run as applet" from the menu.

Grading

Submissions

Submit the source code (.java file) for your Project1 class.