// helper method to test whether a given earthquake is in a given country
  // This will also add the country property to the properties of the earthquake feature if
  // it's in one of the countries.
  // You should not have to modify this code
  private boolean isInCountry(PointFeature earthquake, Marker country) {
    // getting location of feature
    Location checkLoc = earthquake.getLocation();

    // some countries represented it as MultiMarker
    // looping over SimplePolygonMarkers which make them up to use isInsideByLoc
    if (country.getClass() == MultiMarker.class) {

      // looping over markers making up MultiMarker
      for (Marker marker : ((MultiMarker) country).getMarkers()) {

        // checking if inside
        if (((AbstractShapeMarker) marker).isInsideByLocation(checkLoc)) {
          earthquake.addProperty("country", country.getProperty("name"));

          // return if is inside one
          return true;
        }
      }
    }

    // check if inside country represented by SimplePolygonMarker
    else if (((AbstractShapeMarker) country).isInsideByLocation(checkLoc)) {
      earthquake.addProperty("country", country.getProperty("name"));

      return true;
    }
    return false;
  }
  // 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() {
    // TODO: Implement this method
    int countOceanQuakes = 0;
    int temp = countryMarkers.size();
    for (Marker countryMarker : countryMarkers) {
      int count = 0;

      String countryName;
      countryName = (String) countryMarker.getProperty("name");
      // System.out.println(countryMarker.getProperty("name"));
      for (Marker quakeMarker : quakeMarkers) {

        String quakeCountry;
        quakeCountry = quakeMarker.getStringProperty("country");
        if (quakeCountry == countryName) {

          count++;
        }
        if (quakeCountry == null) countOceanQuakes++;

        // System.out.println(quakeCountry);

        // System.out.println(quakeMarker.getStringProperty("country"));
        // System.out.println(quakeMarker.getProperties());

      }

      if (count > 0) {
        System.out.println(countryName + " number of times the quakes happened: " + count);
      }
    }
    System.out.println("number of ocean quakes: " + countOceanQuakes / temp);
  }
Пример #3
0
 // 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() {
   // TODO: Implement this method
   int total = 0;
   for (Marker country : countryMarkers) {
     int count = 0;
     for (Marker feature : quakeMarkers) {
       if (country.getProperty("name").equals(feature.getProperty("country"))) {
         count++;
       }
     }
     total = total + count;
     if (count >= 1) {
       System.out.println(country.getProperty("name") + ":" + count);
     }
   }
   System.out.println(
       "Number of quakes that were detected in the ocean: " + (quakeMarkers.size() - total));
 }
Пример #4
0
 private void cratersToShow() {
   for (Marker marker : craterMarkers) {
     java.util.HashMap<String, Object> properties = marker.getProperties();
     float diameter = Float.parseFloat(properties.get("diameter").toString());
     properties.put(
         "radius",
         ((diameter / 100) * map.getZoom())); // radius scaling is to match scales of the map
     if (Float.parseFloat(marker.getProperty("diameter").toString()) < requestedCraterSize)
       marker.setHidden(true);
     else marker.setHidden(false);
   }
 }