Storing value in Object and converting them to int

59 Views Asked by At

I am doing an assignment from coursera where I am coding for a map which displays markers to point out the spots where there was an earthquake.So I want to change the color of marker to yellow if the earthquake was after 2000 and to grey if before 2000.In my code ,I have used PointFeature as datatype in ArrayList which stores information like year to for the marker to change color.I am using unfolding maps.

 List<PointFeature> bigEqs = new ArrayList<PointFeature>();
 Location valLoc = new Location(-38.14f,-73.03f);   
 Feature valEq = new PointFeature(valLoc);
 bigEqs.add((PointFeature) valEq);
 valEq.addProperty("title", "Valvidivia,Chile");
 valEq.addProperty("magnitude","9.5");
 valEq.addProperty("date", "May 22,1960");
 valEq.addProperty("year", "1960");
      
 Location valLoc1 = new Location(60.59f,-147.848f);
 Feature alaskaEq = new PointFeature(valLoc1);
 bigEqs.add((PointFeature) alaskaEq);
 alaskaEq.addProperty("title", "Prince William Sound ,Southern Alaska");
 alaskaEq.addProperty("magnitude","9.2");
 alaskaEq.addProperty("date", "March 28,1964");
 alaskaEq.addProperty("year", "1964");
   
 Location valLoc2 = new Location(3.30f,95.98f);
 Feature sumantraEq = new PointFeature(valLoc2);
 bigEqs.add((PointFeature) sumantraEq);
 sumantraEq.addProperty("title", "Sumatra-Andaman Islands ");
 sumantraEq.addProperty("magnitude", " 9.1");
 sumantraEq.addProperty("date", " December 26,2004");
 sumantraEq.addProperty("year", " 2004");
   
   
 Location valLoc3 = new Location(38.30f,142.37f);
 Feature japanEq = new PointFeature(valLoc3);
 bigEqs.add((PointFeature) japanEq);
 japanEq.addProperty("title", "Tohuku(Eastern coast of Honshu) ,Japan");
 japanEq.addProperty("magnitude", " 9.1");
 japanEq.addProperty("date", "November 3 , 2011 ");
 japanEq.addProperty("year", "2011 ");
   
 Location valLoc4 = new Location(52.62f,159.78f);
 Feature kamchatkaEq = new PointFeature(valLoc4);
 bigEqs.add((PointFeature) kamchatkaEq);
 kamchatkaEq.addProperty("title", "Kamchatka,Russia ");
 kamchatkaEq.addProperty("magnitude", " 9.0");
 kamchatkaEq.addProperty("date", "April 24,1952 ");
 kamchatkaEq.addProperty("year", " 1952");
 
 List<Marker> markers1 = new ArrayList<Marker>();
 for(PointFeature eq:bigEqs) {
       markers1.add(new SimplePointMarker(eq.getLocation(),eq.getProperties()));
       
  }  for(Marker mk:markers1) {
     if(  mk.getProperty("year")>2000) {
         mk.setColor(color(255,255,0));
     }else {
         mk.setColor(color(128,128,128));
     }
     map.addMarker(mk);
 }

But it showing error:that it cant cast obj to int here, if( mk.getProperty("year")>2000)

1

There are 1 best solutions below

0
On

Since the year is a number, if you parse it into an int it will work.

Example:

if(Integer.parseInt(mk.getProperty("year"))>2000)

This will work.