Java: Overview In this task, you will read data from a text file, process the loaded data, and then save the processed data to a new text file. The purpose is to teach you to read from and save to...


Java:


Overview
In this task, you will read data from a text file, process the loaded data, and then save the processed data to a new text file. The purpose is to teach you to read from and save to text files.
Task
Statistics department in Germany has made forecasts of what Germany's population will look like by 2050, distributed by age and gender. The text file (population2050.txt) contains statistics on the estimated population for the year 2050. The figure below shows the first 16 lines of the file.


First comes a line that shows which age group the information applies to. This is followed by a row with information on the number of men in that age group, followed by a row with the number of women in that age group. In total, the file contains information for the age groups 0 to 105 and the information about each age group extends over three lines as shown. The rows with information about the number of men and women are formatted using one or more spaces.


Your task is to write a java program that loads data from the file (population2050.txt) and for each age group calculates the total number of people (adds the number of men and women). The program should also calculate the total population. The result must be written to a new file and at the same time presented on the screen according to the figures in the next picture.


The figure below shows examples of the printing that is done while the program is running.


The figure below shows the contents of the file the result is saved to. Note that the two rows of dots (………) have been manually added to display both the beginning and the end of the file.


The formatting does not have to look exactly like in the figures, but must be formatted as follows:
• The headings 'age' and 'number' should appear at the top of the file (printout on the screen).


• At the bottom of the file (printout on the screen), the total population should be printed.
• On each line between the top and bottom, each age group should be printed (0-105) followed by the total number of people within that age group.
Tip
PrintWriter also includes the format method for formatting the printout.
Use the Scanner class to load data from the file, or use StringTokenizer (preferably String.split) if you are reading data with FileReader.


Note! In your code, you may not hardcode the number of rows or age groups in the file.


population2050 - Notepad<br>File<br>Edit<br>View<br>Men<br>61240<br>Women<br>57806<br>1<br>Men<br>61396<br>Women<br>58199<br>2<br>Men<br>61415<br>Women<br>58312<br>3<br>Men<br>61409<br>Women<br>58287<br>4<br>Men<br>61342<br>Women<br>58228<br>Men<br>61225<br>Women<br>58165<br>6<br>Men<br>61086<br>Women<br>58056<br>

Extracted text: population2050 - Notepad File Edit View Men 61240 Women 57806 1 Men 61396 Women 58199 2 Men 61415 Women 58312 3 Men 61409 Women 58287 4 Men 61342 Women 58228 Men 61225 Women 58165 6 Men 61086 Women 58056
java Task2<br>To which file should the result be saved? test.txt<br>Age<br>Quantity<br>119046<br>119595<br>119727<br>119696<br>119570<br>119390<br>119142<br>118904<br>118674<br>118458<br>8.<br>9.<br>10<br>118225<br>11<br>118022<br>test.txt - Anteckningar<br>Arkiv Redigera Format Visa Hjälp<br>Age<br>Quantity<br>119046<br>1<br>119595<br>2<br>119727<br>3<br>119696<br>4<br>119570<br>119390<br>119142<br>99<br>2787<br>100<br>1913<br>101<br>1275<br>102<br>816<br>103<br>489<br>104<br>281<br>105<br>297<br>Total: 10516421|<br>Rad 20, kol 16<br>100%<br>Windows (CRLF)<br>UTF-8<br>

Extracted text: java Task2 To which file should the result be saved? test.txt Age Quantity 119046 119595 119727 119696 119570 119390 119142 118904 118674 118458 8. 9. 10 118225 11 118022 test.txt - Anteckningar Arkiv Redigera Format Visa Hjälp Age Quantity 119046 1 119595 2 119727 3 119696 4 119570 119390 119142 99 2787 100 1913 101 1275 102 816 103 489 104 281 105 297 Total: 10516421| Rad 20, kol 16 100% Windows (CRLF) UTF-8
Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here