A Zip archive containing the files for the assignment is provided in Minerva. When you unzip it, you should see three files of earthquake data, along with four .java files. One of these, QuakeException.java, is complete and ready for you to use; the other three files containing empty Java classes.
There are ‘To Do’ comments inside the classes that summarise the code that you need to write, and detailed step-by-step instructions are provided below.
Before you begin programming, take some time to study the sample data. You can use a spreadsheet application to do this. Each row in the dataset represents a single earthquake. The different columns represent various parameters measured for an earthquake. You don’t need to know what most of these are, although further details can be found at the USGS Earthquake Hazards Program website if you are interested. The only columns relevant to this assignment are: latitude, longitude, depth and magnitude.
<标题>Note that filenames consist of two parts: a severity level (often expressed in terms of earthquake magnitude) and a time period. The two parts are separated by the underscore character. Thus, 2.5_day.csv contains details of earthquakes of magnitude 2.5 or greater, recorded over a single day; 4.5_week.csv records earthquakes of magnitude 4.5 or greater, over a one-week period; and significant_month.csv records ‘significant’ earthquakes recorded during a one-month period.
2 Quake Class
This class encapsulates the details a single earthquake.
1. Edit Quake.java in a text editor. Add to the class fields that represent the latitude, longitude, depth and magnitude of an earthquake.
<标题>2. Create a constructor for Quake that takes a single String parameter. This string represents all of the data provided by the USGS for a single earthquake, with each value separated from the others by commas. To see real examples of what this string looks like, open one of the data files in a text editor (not in a spreadsheet), and examine any of the lines after the first. Note: you can use a method of the String class to help you implement this. Your constructor should perform some basic validation, checking that latitude is within the allowed range of ?90.0 ? to 90.0 ? , and that longitude is within the allowed range of ?180.0 ? to 180.0 ? . You should throw an instance of QuakeException, containing an appropriate error message, if latitude or longitude are invalid.
<标题>3. Write simple ‘getter’ methods for each of the fields. These methods should simply return the values of the fields.
4. Write a toString method for Quake. This should generate and return a string representation of the Quake object. The string should contain magnitude, depth, latitude and longitude, in that order, formatted like this example: M5.0, 12.6 km, (35.4975°, 141.0217°) Note: the ‘degrees’ symbol can be generated with the Unicode escape sequence \u00b0. As you complete each step of implementing this class, remove the corresponding ‘To Do’ comment and check that your code compiles. Once you’ve written the constructor and getter methods, you can test them by writing a small program that creates a Quake object from a string. You can use one of the lines from the given data files as the string.