Note! In your code, you may not hardcode the number of rows or age groups in the file. And the program will ask the user to write the name of the textfile for the output. 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. Can u attach a screenshut that the code working
Note! In your code, you may not hardcode the number of rows or age groups in the file.
And the program will ask the user to write the name of the textfile for the output.
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.
Can u attach a screenshut that the code working
Step by step
Solved in 5 steps with 4 images