These questions require you to create several structures.
Top ten countries.
Print the ten largest countries by population, in descending order.
You could make a TreeMap where the key started with the population - that way the last entry would be the biggest country.
295000000USA (name:'USA',region:'North America',area:9800000sqkm,pop:295000000,gdp:12213000000000)
1100000000India (name:'India',region:'Asia',area:3100000sqkm,pop:1100000000,gdp:682000000000)
1300000000China (name:'China',region:'Asia',area:9600000sqkm,pop:1300000000,gdp:1677000000000)
*You would need to make sure that the numbers were padded with enough spaces (15 should be plenty)
*You would use the method
lastKey to get to the one at the end.
*You would use the method
lowerKey to get the one before that.
test text
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.
test text
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.
You may not change the TreeMap object within the loop that runs over the list of values. So the following is not permitted:
for (Country c : world.values()){
if (...)
world.remove(c.name);
}
You can create a second structure to store the names of the countries to be removed:
TreeMap<String,Country> doomed =
new TreeMap<String,Country>();
for (Country c : world)
if (...){
...
doomed.put(c.name,c);
}
for (String n:doomed.keySet())
world.remove(n);
test text