We create our own TreeMap objects.
Print every region once
To print each region we must create our own list
regionList.
As we process each country we add the region to our list. The
value we put in does not matter, we can use anything. Some regions
will be added many times - this doesn't matter each simply over-writes
the previous.
Print each region just once.
There are two loops in the code. In the first loop we go over every country in the structure world which has been given.
The second loop goes over the structure created.
Initially the first loop simply prints each region. Instead it
should add the region to regionList.
regionList.put(c.region, 1);
test text
The number of regions.
Print the number of regions.
You can look at the documentation for this:
TreeMap
test text
Number of countries in each region.
The program shown creates a new TreeMap called rList
- we put in every region of the world.
Print the number of countries in each region. Use 35 characters
for the region and 3 characters for the number.
For each country you should add 0 against that region if the region is not in the region list.
if(!regionList.containsKey(c.region))
regionList.put(c.region, 0);
Having done that you can now add 1 to whatever value was already in regionList
regionList.put(c.region,regionList.get(c.region)+1);
test text
Number of large countries in each region.
For each region show the number of countries with a population
of at least 10 million.
The line:
regionList.put(c.region,
regionList.get(c.region)+1);
is where you add to the count of big countries per region.
You should only do this if the country has a big population.
test text
Show the total population of each region
For each region show the total population.
To add the current population
rpop.put(c.region,rpop.get(c.region)+c.pop);
test text
List large regions.
Print region and total population for those regions
with a total population of at least 100 million.
Use 35 characters for the region name and 13 characters for
the total population.
test text