Programming Assignment #2       Due Midnight October 11, 2004

Create a GUI based program that reads in from Wilmington NC 100 year Hurricane Data to create Hurricane objects with the following instance data:

YEAR MONTH STORM ID STORM NAME PRESSURE(MB) WIND SPEED(MPH) CATEGORY

Use a naming convention that clearly identifies the purpose of each class, method,  and field. Some methods and fields should be static to ensure the desired behavior, i.e. a sortField should be common to all instances. Your Hurricane objects must implement the Comparable interface. The compareTo method should be written to compare by any of the object's fields with at least three fields concatenated to break ties, except in the case of the unique ID where there should be no ties. Compare by category would compare category, year, then name. Compare by wind speed would compare wind speed, year, then name.

Your Hurricane objects must override the toString method to display each of the fields in the order shown. The fields should be formatted (padded with leading blanks so as to each take up the same amount of space as its respective heading. Do not display any fields other than those listed above.

When adding Hurricane objects to the Hurricane array only unique storm ids may be used. The data provided lists multiple instances of an id, but your array should contain only that id with the highest wind speed1.

Your GUI should display the field table above, with hurricanes listed below. Develop menus and menu items that include

  1. saving the table complete with entries to a  text file
  2. sort by each field as a menu option (Note: the background of the field heading chosen to sort by should display in a distinctive color.)
  3. open the file saved and display its contents
  4. open url to create hurricane objects (Contents of this file may change, but its layout will not be changed.) 
  5. ability to add a hurricane to the data array by hand, as a menu option that creates a new default hurricane with today’s year and month, not named, and the rest of the fields not empty but editable.
  6. optionally, add a search menu that can search by any field -multiple hits need not be accounted for.

Your GUI should have an analyses pane (JLabel) that answers the questions Which month has the most H5, H4, H3, H2, and H1 category hurricanes.

Data is based on a query of http://hurricane.csc.noaa.gov/hurricanes/ for all category H1-5 hurricanes within 65 nautical miles of zip code 28403 from 1903-2003.


Discussion:

 

  1. Use the web page provided as your unfiltered database. You will have to search and pick the data required for each Hurricane. Once you have the required data for a Hurricane instance, you can create the object and add it to your array. The database is used only once.
  2. From there on, you will manipulate your array of Hurricane objects, vary the display based on the sort criteria, save and load a file (text is easiest and provides ease of readability using notepad) with this filtered data.
  3. The text file is for your convenience and use. I would only save or load based on menu input by the user. Perhaps auto-save once after the Hurricane array has been created.
  4. The analyses pane is to ensure at least one (and one is enough) comprehensive analyses is performed. The question to be answered is "Over the entire 100 year database, which month produced the most H5, which month produced the most H4,…, hurricanes in our region?"
  5. Perhaps an optional feature would be the ability to edit existing Hurricane instances.

 

As for the rest of the details, they are up to you.

//temp is an array of Hurricanes each with unique ID but not necessarily the highest windspeed and category for each
// see October 1, code Test1.java for tips on creating temp[] with this precondition
//hurricanes is presorted so ids are sequential (should already be sorted by year and ID)

//in the outer loop below cycle through temp and in the inner loop -compare to hurricanes with same id
int maxSpeed, maxIndex = 0;
boolean haveUpdate = false;
for (int i = 0, j = 0; i < temp.length; i++) {
   maxSpeed = temp[i].getWindSpeed();

   for(; j < hurricanes.length && temp[i].getID().equals(hurricanes[j].getID()); j++) {
      if (hurricanes[j].getWindSpeed() > maxSpeed) {
         haveUpdate = true;
         maxIndex = j;
      }
   }
   if (haveUpdate) {
      temp[i] = hurricanes[maxIndex];
      haveUpdate = false;
   }
}
hurricanes = temp;