Searching Earthquake Data(2)

2017-11-2(四)

Programming Exercise: Searching Earthquake Data(2)

今天完成剩下4個assignment

  1. Filtering by Depth

  2. Filtering by Phrase in Title

  3. Finding the Closest Earthquakes to a Location

  4. Finding the Largest Magnitude Earthquakes

Assignment 2: Filtering by Depth

  • 基本的depth大小判定

  • Output 圖片

Assignment 3: Filtering by Phrase in Title

  • 關鍵在判斷出phase在info的哪一個位置,是start, end, any三種情況,

  • title.startsWith(phrase) 這是重要語法

  • 如圖:

Assignment 4: Finding the Closest Earthquakes to a Location

  • 因為不是找出最短距離,而是找出最小的4個最短距離,所以要有index去判斷每一個排序的data

  • 如圖:

  • 關鍵code如下:

Assignment 5: Finding the Largest Magnitude Earthquakes

  • 關鍵在於判斷,ArrayList largest是否已經達到 howMany的上限,還有dataRemovable裡面是否還有data,並且在執行每一次步驟時,dataRemovable裡的data要移除

  • 結果圖:

總結:

  • 我覺得簡單的filter不見得就代表容易,很多skill還要逐步積累,儘管上述assignment並不是太難,但我已經花了早上將近3-4小時去implement,我明白現在還很菜,不過我知道我會越來越好的,重點是要好好做好每一個步驟。

  • 當中有很多問題,像是pharse的判斷,我就不知道有startsWith() 這個語法,還有第五題我也不知道要用while,這些後來是參考別人的思路,然後才寫出來的。

  • 儘管是參考他人,也要問自己,下次要用這個方法,會用在哪些場景中?能找到哪些data?

  • 根據過往經驗,與其快速下一個我學到很多的經驗,不如留一些問題給自己,以便日後再回來看此筆記時,看看自己有沒有進步。

  • 這種找前三名、倒數5名的邏輯,是否能用while以外的用法呢?

Last updated

Was this helpful?