Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN JAVA! . Goto: http://earthquake.usgs.gov/earthquakes/map/ . In the top left,

ID: 3574914 • Letter: I

Question

IN JAVA! . Goto: http://earthquake.usgs.gov/earthquakes/map/ . In the top left, click the downward arrow, click download and select “CSV”. You can drag this into Netbeans to see the data.

For each line in the file, find the part in quotes (there should only be one). This is the place where the earthquake happened. Print this location for each line in the file

Example:

9km S of Emajagua, Puerto Rico

9km S of Emajagua, Puerto Rico

160km WNW of Iranshahr, Iran

68km NE of Road Town, British Virgin Islands

88km NW of Larsen Bay, Alaska

...

Explanation / Answer

Java Program:

package com.files.reader;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LocationFinder {

   /**
   * @param args
   * @throws IOException
   */
   public static void main(String[] args) throws IOException {

       // Reading the csv file line by line in Java using BufferedReader
       FileInputStream fis = null;
       BufferedReader reader = null;

       //Path to the csv file
       fis = new FileInputStream("C:\tests\2.5_day.csv");
       reader = new BufferedReader(new InputStreamReader(fis));

       String line;
       String location;
       // Skip the first line as it stores only the name of columns
       reader.readLine();
      
       System.out.println("******* Earthquake Locations********");
       while ((line = reader.readLine()) != null) {
          
           // Compile a pattern that matches string inside quotes: "<location>"          
           Pattern pattern = Pattern.compile(""(.*?)"");
          
           // Match the pattern with line          
           Matcher matcher = pattern.matcher(line);
          
           // If a match is found  
           if (matcher.find()) {
               location = matcher.group(1);
           // Print the found location              
               System.out.println(location);
           }
       }
       reader.close();
       fis.close();
   }
}

--------------------------------------------------------------------

Sample Output:

******* Earthquake Locations********
51km SE of Lakeview, Oregon
57km SSE of Shihezi, China
10km S of Emajagua, Puerto Rico
50km ENE of Hirara, Japan
8km S of Emajagua, Puerto Rico
38km SW of Bilungala, Indonesia
10km S of Emajagua, Puerto Rico
41km SW of Ashkasham, Afghanistan
21km SE of Clinton, Montana
99km NE of Road Town, British Virgin Islands
110km SW of Kota Ternate, Indonesia
42km SSW of Amukta Island, Alaska
44km ENE of Maneadero, B.C., MX
9km SW of Reuleuet, Indonesia
38km N of Amahai, Indonesia
15km WSW of Kaikoura, New Zealand
65km E of Chignik Lake, Alaska
116km SE of Muara Siberut, Indonesia
36km ESE of San Ignacio, Peru
5km WNW of La Parguera, Puerto Rico
147km WSW of Vaini, Tonga
5km WSW of La Parguera, Puerto Rico
101km WNW of Kota Ternate, Indonesia
52km NE of Punta Cana, Dominican Republic
54km SSW of Cantwell, Alaska