Difference between revisions of "Harder TreeMap Tutorial"

From Progzoo
Jump to: navigation, search
(Dominated Regions)
(Colombia takes all.)
Line 196: Line 196:
 
   TreeMap<String,Country> saCopy =
 
   TreeMap<String,Country> saCopy =
 
       new TreeMap<String,Country>();
 
       new TreeMap<String,Country>();
   for (String n:world.keySet()){
+
   for(String n:world.keySet())
 +
  {
 
     Country c = world.get(n);
 
     Country c = world.get(n);
 
     if (c.region.equals("South America") &&
 
     if (c.region.equals("South America") &&
       !c.name.equals("Colombia")){
+
       !c.name.equals("Colombia"))
 +
    {
 
       col.area += c.area;
 
       col.area += c.area;
 
       col.pop  += c.pop;
 
       col.pop  += c.pop;
Line 207: Line 209:
 
   }
 
   }
 
   for  (String n:saCopy.keySet())
 
   for  (String n:saCopy.keySet())
 +
  {
 
     world.remove(n);
 
     world.remove(n);
 +
  }
 
}
 
}
 
]]></answer>
 
]]></answer>
 
</question>
 
</question>
 
{{TreeMap Tutorial}}
 
{{TreeMap Tutorial}}

Revision as of 20:44, 12 September 2012

These questions require you to create several structures.

Top ten countries.

Print the ten largest countries by population, in descending order.


[Font] [Default] [Show] [Resize] [History] [Profile]

Dominated Regions

A dominated region is one where a country has more than 50% of the region population. Print the name of the dominated region and the country which dominates it.

[Font] [Default] [Show] [Resize] [History] [Profile]

Colombia takes all.

Plucky Colombia takes over the whole of South America, transfer all resources to Colombia and remove every other country of South America.


[Font] [Default] [Show] [Resize] [History] [Profile]