Dealing with checked Exceptions ..eading and writing to files From a file you cr
ID: 3880702 • Letter: D
Question
Dealing with checked Exceptions ..eading and writing to files From a file you create make at least 4 lines of Strings separated by a space Kevin Rees $23,567.89 Carson Nash $12,456.78 Dustin Mattingly $34,789.34 Walker Bolen $67,890.01 Assume the data file is correct and all are String data types and each line is in the form of: Read the line Parse the line to Lastname, FI. Salary You may use 2 methods: nameParsed and fixSalary (you do not have toooooooo!!) use String.split(regrex) to parse the line into an array of 3 parts [0]--first name [1]- last name [21- string salary The output, which is written to a file, should look like: Rees, K. Nash, C.12456.78 Mattingly, D. 34789.34 Bolen, W. 67890.01 23567.89 Total :138704.02 Average :34676.01 Suggestions Make a priority task list Design an algorithmm Paper code the modules Work one task at a time.Explanation / Answer
Task list (tasks are in order of priority):
T1. Read and parsing the data from input file
T2. Calculate the average and total salary/ Prepare the data to be stored
T3. Store data in the output file
Algorithm:
Step 1: Read person data from input file
Step 2: Parse the line and separate out FirstName, Full Name and Salary in a array
Step 3: Convert salary into double data type
Step 4: Store data into the array in the format (FullName, Salary), where FullName = LastName.<<First letter of first name>>
Step 5: TotalSalary = TotalSalary + salary of the current employee
Step 6: Repeat step 1 to 5 till all records are read and append entire information in an array
Step 7: Calculate average salary by total salary/ total number of employees in array
Step 8: Iterate over the list of employees in the array created in Step 6 and store data in the output file line by line
Step 9: Store total salary value using TotalSalary variable into output file
Step 10: Store average salary value into output file
In above algorithm, Task 1 and 2/Module 1 and 2 are being performed parallely and and will be calculated at Step 7
Module 3: Step 8 to 10
To perform one task at a time, calculation of total salary can be done once all the records are parsed and filled in array step 5 and 6 can be swapped.
Algorithm 2: (One task at a time)
Step 1: Read person data from input file
Step 2: Parse the line and separate out FirstName, Full Name and Salary in a array
Step 3: Convert salary into double data type
Step 4: Store data into the array in the format (FullName, Salary), where FullName = LastName.<<First letter of first name>>
Step 5: Repeat step 1 to 5 till all records are read and append entire information in an array
Step 6: TotalSalary = 0
Step 7: Read salary of employee from array created in step 5
Step 8: TotalSalary = TotalSalary + salary of the current employee
Step 9: Iterate over the array till end of array
Step 10: Calculate average salary by total salary/ total number of employees in array
Step 11: Iterate over the list of employees in the array created in Step 5 and store data in the output file line by line
Step 12: Store total salary value using TotalSalary variable into output file
Step 13: Store average salary value into output file
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.