Question: The file USPopulation.txt contains integer values representing the midyear population of the United States, in thousands during the years 1950 through 1990. The first line

The file USPopulation.txt contains integer values representing the midyear population of the United States, in thousands during the years 1950 through 1990. The first line in the file contains the population for 1950. Its value is 151868 which represents the actual value 151,868,000 The second line is 153982 for 1951, and so forth up to 249623 for 1990.

For Part-A you write a Java program to read the files contents into an array and then process this array according to instructions given below for Part-A.

For Part-B you write a Java program to read the files contents into an ArrayList and then process this ArrayList according to the same instructions as for Part-A.

The output from these two parts should be identical. Part-A uses an array. Part-B uses an ArrayList.

The requirements for your output file. Refer to the sample output: Asg-1_AB_Output.txt to guide you in your programming.

a)Print headings for the output as shown in the sample output file.

b)On each line:

1.Print the year applicable,

2.Print the population for that year in millions with extra zeros.

3.Print the Difference of population from the previous year. (Of course, this value is blank for the first year in the list.)

4.Use format control to print the values for Year, Population value and Difference from previous year. How to display formatted output is discussed in section 3.10 beginning on page 164 of your textbook.

5.Format specifier syntax begins on page 167. This allows you to control field size and position of commas in output.

c)You also need to find:

1.the average population;

2.the average population difference from year-to-year;

3.the greatest population increase and the year-to-year in which it occurs;

4.the smallest population increase and the year-to-year in which it occurs.

d)Print these values at the end of the list as shown in the sample output.

USPopulation.txt:

151868 153982 156393 158956 161884 165069 168088 171187 174149 177135 179979 182992 185771 188483 191141 193526 195576 197457 199399 201385 203984 206827 209284 211357 213342 215465 217563 219760 222095 224567 227225 229466 231664 233792 235825 237924 240133 242289 244499 246819 249623

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!