Free Writing
  • Introduction
  • 過去、現在、未來(1)
  • Searching Earthquake Data(1)
  • Searching Earthquake Data(2)
  • test
  • Recommendation week1
  • An Alert for the World
  • 容錯系統(一)
Powered by GitBook
On this page
  • Programming Exercise: Searching Earthquake Data(1)
  • Before assignments:

Was this helpful?

Searching Earthquake Data(1)

Previous過去、現在、未來(1)NextSearching Earthquake Data(2)

Last updated 6 years ago

Was this helpful?

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:

Assignment 1: Filtering by Magnitude and Distance:

  • 此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

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

會看到圖2:

結果如圖3

Assignment 1 code link