Searching and Sorting

Continue Lab11a.

Create a GUI based program to gather data from http://torvalds.bearlabs.uncw.edu/~tompkinsj/221/Fall04/p2/hurricaneData03_03.htm. To save time, use Lab11b.java as a starting point if your Lab11a does not yet load the double string array (add your name to the @author javadoc comment in the header.)

Define a Hurricane class that implements the Comparable interface and has Static constants Y, M, ID, N, S, and C that correspond to the String fields year, month, stormID, stormName, windSpeedMPH, and category. There should also be a static int named sortField with corresponding static mutator and accessor methods. Use this Hurricane.java as a starting point if desired.

Determine how many rows in your double array are not null. Use one less than this value to instantiate an array of Hurricanes (we will not be using the 0th row with header data to instantiate a Hurricane.) Instantiate each Hurricane with the selected fields. Comment out the method used to display your double string array (displayStrA) and call a method to display the Hurricane array after it has been created.

Add a Sort menu with menu items corresponding to the various sort fields. For the purpose of this lab, only the sort by wind speed needs to be implemented. The current implementation of the Comparable interface in the Hurricane class uses only the String class compareTo method. This does not provide the desired result as the string "75" follows the string "135". Modify the compareTo method to correct this deficiency. One technique is to compare the int values of the wind speeds then assign a large positive, negative, or zero value, then further adjust this value with the return value of the concatenation of the strings year and name used with their compareTo method:

int thisSpeed, otherSpeed;
            thisSpeed   = Integer.parseInt(this.windSpeedMPH);
            otherSpeed = Integer.parseInt(otherHurricane.windSpeedMPH);

if (thisSpeed - otherSpeed > 0) value = 133;

                                    if (thisSpeed - otherSpeed == 0) value = 0;

                                    if (thisSpeed - otherSpeed < 0) value = -133;

                                    int addedValue = (this.year + this.stormName)

                                                            .compareTo(otherHurricane.year + otherHurricane.stormName);

                                    value += addedValue;

                                    break;

Write a selection sort routine to sort this array by the specified field.

Display the sorted hurricane array after sorting.

Write a binary search routine (see 20 September Lecture notes: SearchRoutines.java) to search this array for a name. Display the Hurricane data for a successful search in the label. For an unsuccessful search display the value searched for and "Not Found" in the label. Input for the user should not require correct capitalization.

Email your completed Lab11.java and Hurricane.java files as attachments to either CSC221.001@uncw.edu or CSC221.002@uncw.edu.