CIS191-s12/Project 12

From MCIS Wiki
Jump to: navigation, search

Due: Wednesday, April 18

Maps: Part 1

This application deals with the algorithm at the heart of Google maps. We will read in map data that contains descriptions of cities and roads, as entered on a spreadsheet and represented by a CSV file.

In part 1, you will read in this data and print it back out.

The City Class

A city is defined by the following information:

  • A name
  • An x, y coordinate (integers) of its placement of the map
  • A set of roads that connect to the city

Create a class that represents a city. Include a toString method and an equals method. Two cities are equal if they have the same name.

The City class should contain a static ArrayList of all cities. A static function in the city class takes a city name and returns the city of that name or null.

The Road Class

A road has the following:

  • A start city
  • An end city
  • A length (integer)
  • A travel time (integer)
  • A name

Create a Road class with a constructor and toString method.

The Input File

The input is created by Excel and saved as a csv file. The spreadsheet is divided into two parts: one for cities and one for roads. These are separated by an empty row - you can test for a city with an empty name to detect the separation between cities and roads.

Each line on the city part of the sheet contains a city name, X coordinate, and Y coordinate.

Each line on the road part contains a road name, two cities, a mileage, and a travel time.

Here is a small example:

Grand Junction,64,256,,
US 50,Grand Junction,Delta,43,57
US 50,Delta,Montrose,23,30
US 50,Montrose,Gunnison,65,76

Read the input file (you can wire the file name into your code) and create objects based on the above classes. Print an error message and exit the program if a road refers to a city that hasn't been defined earlier. Note that each road in the spreadsheet should create two Road objects - one leading in each direction.

Printing a Report

Test your code by printing a report that lists each city and the roads leading out of it. Format this report as shown below.

Delta is at (108, 291)
  US 50 goes to Grand Junction (43 miles, 57 minutes)
  US 50 goes to Montrose (23 miles, 30 minutes)
Grand Junction is at (58, 251)
  US 50 goes to Delta (43 miles, 57 minutes)
Montrose is at (127, 325)
  US 50 goes to Delta (23 miles, 30 minutes)


Create a JFrame form for your program. At present, it should just have a single button: load map. Use the code that you used in Maze Runner to attach a file chooser to this button. When pressed, read a csv file and then print a report as described above.