Here is Canada's population over the past 150 odd years:
Canada's Total Population
1861: 3230000
1871: 3689000
1881: 4325000
1891: 4833000
1901: 5371000
1911: 7207000
1921: 8788000
1931: 10377000
1941: 11507000
1951: 13648000
1961: 18238000
1971: 21568000
1981: 24820000
1991: 28031000
2001: 31111000
Start with below program (population.java) and make the additions specified:
public class population
{
public static void main (String args [])
{
int size = 15;
//the array with Canada's population in it
int a [] = {3230000, 3689000, 4325000, 4833000, 5371000, 7207000, 8788000,
10377000, 11507000, 13648000, 18238000, 21568000, 24820000, 28031000, 31111000};
printpop (a, size);
}
public static void printpop (int a [], int size)
{
System.out.println ("Canada's Total Population");
for (int i = 0 ; i < size ; i++)
{
//Calculate with year we are in
int year = i * 10 + 1861;
System.out.println (year + ": " + a [i]);
}
}
}
1. Add a method called public static void popIncrease (int a [], int size) that will print out the following:
Canada's Population Increase
1871: 459000
1881: 636000
1891: 508000
1901: 538000
1911: 1836000
1921: 1581000
1931: 1589000
1941: 1130000
1951: 2141000
1961: 4590000
1971: 3330000
1981: 3252000
1991: 3211000
2001: 3080000
2. Add a method public static int minIncrease (int a [], int size) which will find the year that had the smallest population increase - 1871.
3. Add a method public static int maxIncrease (int a [], int size) which will find the year that had the largest population increase - 1961.
4. Add a method public static int avgIncrease (int a [], int size) which will find the average population increase - 1991500.