0% found this document useful (0 votes)
68 views2 pages

Lab Assignment 1.1: Phase 1: Sorting Earthquake Data

This document outlines the first phase of a three-phase lab assignment on sorting earthquake data. In phase 1, students are tasked with: 1) Loading over 157,000 earthquake records from a data file into EarthquakeRecord objects; 2) Creating three additional arrays to reference the same EarthquakeRecord objects; and 3) Sorting each of the three new arrays using a different sort criteria. The document provides existing code to parse the earthquake data and describes the required steps to duplicate the original array into three new arrays and sort each one using a different Comparator.

Uploaded by

Amany Shousha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
68 views2 pages

Lab Assignment 1.1: Phase 1: Sorting Earthquake Data

This document outlines the first phase of a three-phase lab assignment on sorting earthquake data. In phase 1, students are tasked with: 1) Loading over 157,000 earthquake records from a data file into EarthquakeRecord objects; 2) Creating three additional arrays to reference the same EarthquakeRecord objects; and 3) Sorting each of the three new arrays using a different sort criteria. The document provides existing code to parse the earthquake data and describes the required steps to duplicate the original array into three new arrays and sort each one using a different Comparator.

Uploaded by

Amany Shousha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

CST8130:

Data Structures
Lab Assignment 1.1: Phase 1: Sorting Earthquake Data
Introduction EarthquakeRecord objects yet exist. The file processing reads
one single line of text at a time, and sends that single line of
This lab activity involves more detailed work which will split text to the EarthquakeRecord constructor. The constructor
into three sequenced lab assignments. These three phases
parses the raw text into data-typed fields and returns a
will span three weeks of lab periods. I will publish separate
reference to the newly created object (and of course, a
requirements for each of the 3 phases. Each week, I will reference is really the location information for the newly
expect to see the results of the current phase. created object). That reference value is then stored in the
In phase 1, you will: next available element in the array.
• Load 157,015 earthquake records from a 20 File processing continues until all data has been parsed into
megabyte file. The resulting 157,015 the tens of thousands of EarthquakeRecord objects.
EarthquakeRecord objects will all exist as
independent objects, but be managed using an array Step 1: Build Existing Code
of references. This coding is already implemented. To prove that it works, try first running it in the non-Debug
You need only capture the required .java files and mode. On my machine, in the non-Debug mode, it takes less
the data file; then build a project and run. than 1 second to read and parse the 20MB of data. In the
• Create three additional arrays of references to the Debug mode, it takes closer to 10 times as long: about 8
same set of EarthquakeRecord objects. seconds on my computer.
• Sort each of those three new arrays, using a To prove that the original code does work, I suggest setting a
different sort sequence. To do this, you will use the breakpoint and inspecting the data after file processing has
Arrays.sort() algorithm along with suitable completed. Note the diagram below:
Comparator objects.
In subsequent phases, you will implement a recursive Merge
Sort algorithm to sort the data set on at least three different
key fields . . . but that will come next week.

Existing Code: The Classes


You have been provided will a .zip file that contains a 20 MB
1
file of earthquake data , along with source code that already
successfully reads and parses the data. Extract the files; build Breakpoint
a project using the .java files, and run the program. It should
work as is.
The application currently has three classes:
• EarthquakeRecord: This class defines the instance
variables (fields) associated with a single earthquake
record. It also handles the parsing process (that is,
the conversion of the raw source text into the When program execution encounters the breakpoint (after
internal representation of data). nearly 8 seconds on my machine under debug), Eclipse
• EarthquakeDataSet: This class is the container that switches to the Debug view and offers me the opportunity to
manages all instances of EarthquakeRecord. inspect accessible variables.
Currently, it manages the individual
Note in the following diagram that I have opened the
EarthquakeRecord instances through an array of
reference variable eqds. You can see that it contains the
references.
integer value 35 (which is the location information for the
• EarthquakeTest: This implements a main() routine 2
EarthquakeDataSet object ). Inside this object I see several
used to exercise the first two classes.
instance variables. The first three (aeqrCitySort,
Existing Code: Processing Steps aeqrDepthSort, aeqrMagnitudeSort) hold the value null (that
is, they are not yet referencing anything).
EarthquakeDataSet creates an array of references to
The fourth variable is aeqrOriginalOrder. This is the reference
EarthquakeRecord objects. Of course, that array is initially
to the array that holds references to the tens of thousands of
populated with endless null values, since no actual
EarthquakeRecord objects. On my machine, it stores the
1 2
The data file captures hundreds of years of earthquake The number 35 may differ on your run, since the runtime
events. location of objects may differ.
3
integer value 35. Of course, the specific integer value doesn’t can use the Arrays.sort() method . Ultimately, you will call
matter. What does matter is that this number represents Arrays.sort() three times, once for each of the three array
location information for the array of references that was copies. On each call to Arrays.sort(), you’ll need to supply a
created earlier during program execution. Because this is a suitable Comparator object (much like you did in the exercise
reference to an array, I can open it to view the array last week).
contents. But because the array is so large (I sized it for
200,000), Eclipse gives me access to selected ranges. In the A word about Plagiarism
diagram below, I have opened the first range (index positions Feel free to use any resources that help you reach your goal.
0 to 9999), and within that, a smaller range (index positions 0 Just remember to provide attribution (a fancy word for
to 99), and finally have begun viewing the first of 157,015 providing credit) for your source. Use someone else’s work
objects. As you can see, this information is about an event but claim it as your own: that’s plagiarism. Use someone
that took place in 1638 in a town called LYNN. else’s work, and provide the attribution: that’s good form.

Submission Requirements
This is only phase 1, so I do not need to see a complete set of
documentation. I will perform a quick review of your working
code and provide comments that will assist in the completion
of phase 2.
Completed code will be worth up to 3 points. (Typically, a full
Lab Assignment is worth 10 points, since it also includes more
documentation and a greater volume of programming.)

Upcoming Steps in Phase 2


I will publish the Phase 2 document next week. It will explore
how you implement the Merge Sort algorithm.
In addition, I will publish detailed specifications about the
required submission format.

Step 2: Create Three Duplicate Arrays


You will be sorting the data based on three different key
fields: a String field, an int field, and a double field. There will
only ever be one set of EarthquakeRecord objects, and four
arrays will reference the one set of objects. You’ll need to
copy the reference id’s from aeqrOriginalOrder into each of
three newly created arrays. The simplest approach involves
the use of the Arrays.copyOf() method.
If you haven’t already done so, it’s time to open the Java API
documentation. You can access it online at:
http://docs.oracle.com/javase/7/docs/api/
If you’ve installed JDK 7 in the same way that I have, you can
access the locally-stored documentation much faster. Mine is
stored at:
C:/Program Files/Java/jdk1.7.0_02/docs/api/index.html
Find the Arrays class and lookup the documentation on the
copyOf() method.

Step 3: Call Arrays.sort() Method 3


In previous exercises, you called the Collections.sort()
Eventually, you will be sorting the data set of values based on method. That was the correct method when using an
your own implementation of merge sort. But for now, you ArrayList collection. In this lab, you’ll be using an array
directly. Thus, you must use Arrays.sort() instead.

You might also like