// TODO: Add the method: public int compareTo(EarthquakeMarker marker) { if (marker.getMagnitude() < this.getMagnitude()) { return -1; } else if (this.getMagnitude() < marker.getMagnitude()) { return 1; } else { return 0; } // return Float.compare(marker.getMagnitude(), this.getMagnitude()); }
// prints countries with number of earthquakes // You will want to loop through the country markers or country features // (either will work) and then for each country, loop through // the quakes to count how many occurred in that country. // Recall that the country markers have a "name" property, // And LandQuakeMarkers have a "country" property set. private void printQuakes() { int totalWaterQuakes = quakeMarkers.size(); for (Marker country : countryMarkers) { String countryName = country.getStringProperty("name"); int numQuakes = 0; for (Marker marker : quakeMarkers) { EarthquakeMarker eqMarker = (EarthquakeMarker) marker; if (eqMarker.isOnLand()) { if (countryName.equals(eqMarker.getStringProperty("country"))) { numQuakes++; } } } if (numQuakes > 0) { totalWaterQuakes -= numQuakes; System.out.println(countryName + ": " + numQuakes); } } System.out.println("OCEAN QUAKES: " + totalWaterQuakes); }
// Helper method that will check if an earthquake marker was clicked on // and respond appropriately private void checkEarthquakesForClick() { if (lastClicked != null) return; // Loop over the earthquake markers to see if one of them is selected for (Marker m : quakeMarkers) { EarthquakeMarker marker = (EarthquakeMarker) m; if (!marker.isHidden() && marker.isInside(map, mouseX, mouseY)) { lastClicked = marker; // Hide all the other earthquakes and hide for (Marker mhide : quakeMarkers) { if (mhide != lastClicked) { mhide.setHidden(true); } } for (Marker mhide : cityMarkers) { if (mhide.getDistanceTo(marker.getLocation()) > marker.threatCircle()) { mhide.setHidden(true); } } return; } } }