> For the complete documentation index, see [llms.txt](https://yenkang-2.gitbook.io/free-writing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yenkang-2.gitbook.io/free-writing/programming-exercise-searching-earthquake-data1.md).

# Searching Earthquake Data(1)

#### 2017-11-1(三)

## Programming Exercise: Searching Earthquake Data(1)

### Before assignments:

* 全部有五個class，分別是Location, QuakeEntry, EarthQuakeParser, EarthQuakeClient, ClosestQuakes
* ***Location***:代表地理資訊的class，來自android 的platform，其中constructors的parameter包含latitude and longitude，還有其中的 method是 **distanceTo**
* ***QuakeEntry***: 他的constructor需要latitude, longitude, magnitude, title, and depth，他有很多種method跟**toString** method.
* ***EarthQuakeParser*** :有一個read method with a string parameter that represents an XML earthquake data file，並且return an ArrayList of QuakeEntry的objects
* ***EarthQuakeClient***:在earthquake 的data file中，去create an EarthQuakeParser and create an ArrayList of QuakeEntry object. 你可以測試此program with method **createCSV** ，來存取ArrayList of earthquake data 並且印出 CSV file，你將會完成這些method，並過濾magnitude and distance in EarthQuakeClient class內，並增加其他method
* ***ClosestQuakes***: 目的是在一個特定的location，去找ten 最近的地震
* 執行createCSV後，結果如圖1: ![](https://4159222350-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LcGjO1pkQQhaNIb3LKJ%2F-LcGjQ1EKvz4qkFsb_oL%2F-LcGjfIgjWgPmUt-Uc8L%2F%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202017-11-01%20%E4%B8%8A%E5%8D%8810.07.18.png?generation=1555076081298639\&alt=media)

#### Assignment 1: Filtering by Magnitude and Distance:

[Assignment 1 code link](https://github.com/YenKang/Java-Programming-Principles-of-Software-Design/blob/master/Assignment%201-%20Filtering%20by%20Magnitude%20and%20Distance/EarthQuakeClient.java)

* 此assignment的目的就是用magnitude跟distance當作filter，來篩選earthquake的資料

**Magnitude**

* 此assignment中，only modify one class, the EarthQuakeClient class:
* 寫method **filterByMagnitude** with tow parameter (ArrayList quakeData, double magMin)，最後return 在quakeData的資料內，magnitude大於magMin的地震資料，然後這個data已經被命名好了，是以ArrayList存取，named\
  answer
* 修改method bigQuakes with no parameters to use **filterByMagnitude**，並且印出那些地震 above a certain magnitude， 這些地震的資料存在ArrayList named **list** ，經過全部修整後，可以去run your program on the file **non20quakedatasmall.atom** for quakes larger than 5.0

會看到圖2: ![](https://4159222350-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LcGjO1pkQQhaNIb3LKJ%2F-LcGjQ1EKvz4qkFsb_oL%2F-LcGjfIij3PmaMuv0MYi%2F%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202017-11-01%20%E4%B8%8A%E5%8D%8811.11.55.png?generation=1555076079925789\&alt=media)

**Distance**

* 寫一個method filterByDistanceFrom，with three parameter (arrayList quakeData, double distMax, Location from)，這會根據某個location，然後計算從該點的距離以內的地震，最後return ArrayList named answer
* 修改一個method **closeToMe** with no parameters to call **filterByDistanceFrom**，舉例來說，找出對某一個specified city，在1000公里內的地震，目前會把這些地震資料存進Arraylist named list
* 結果如圖3 ![](https://4159222350-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LcGjO1pkQQhaNIb3LKJ%2F-LcGjQ1EKvz4qkFsb_oL%2F-LcGjfIkx25X3pzeFjei%2F%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202017-11-01%20%E4%B8%8A%E5%8D%8811.44.52.png?generation=1555076079171534\&alt=media)
