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.
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.
![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
Total: 10516421|
Rad 20, kol 16
100%
Windows (CRLF)
UTF-8](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F359a1891-a6e6-42ff-9fa2-e97930deb46b%2Fad662de4-9abe-4857-8202-c386fbe2d807%2Fjjr4rtg_processed.png&w=3840&q=75)
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F359a1891-a6e6-42ff-9fa2-e97930deb46b%2Fad662de4-9abe-4857-8202-c386fbe2d807%2Fl4wyznk_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)