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.
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
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