Write a file to read the file employeeSalary.data and calculate the and print ou
ID: 3622395 • Letter: W
Question
Write a file to read the file employeeSalary.data and calculate the and print out:the average salary of all the employees
the total of all salaries
print the salary and name of the highest paid employee
print the salary and name of the lowest paid employee
Format all salary information to just the nearest dollar
Here is a link to down load a zipped folder with two files you can use to test your program, the employeeSalary.data file and a smallerEmpoyeeSalary.data file that you can use for your program its testing phase.
EmployeeDataFiles.zip
Each file has the first row with headers for what each column of data is.
The data is separated by a space between columns
column 5 is the salary in dollars
the last column is the employee's name
Your file should work on the small file with 20 employees and the also the large file with over 30,000 employees by just changing the name of the file in your program.
This is a good example of what a real program might do with real data from a large company.
Only upload your java file(s) here when done. Do not upload the data files, I have my own.
The smaller data file should have these results:
Total: $1389889.00
Average salary: $69494
Highest Salary $99651 for Bouloucos,Cristinel
Lowest Salary $40000 for Nooteboom,Guoxiang
You get extra credit if you can put commas in the salary amounts like this:
Total: $1,389,889.00
Average salary: $69,494
Highest Salary $99,651 for Bouloucos,Cristinel
Lowest Salary $40,000 for Nooteboom,Guoxiang
Explanation / Answer
Hope this helps. Let me know if you have any questions. Please rate. :) import java.io.*; import java.text.NumberFormat; import java.util.*; public class EmployeeSalary { public static void main(String[] args) { Scanner s = null; String fileName = "employeeSalary.data"; Person highest = null, lowest = null; ArrayList people = new ArrayList(); double totalSalary = 0; try { s = new Scanner(new FileInputStream(fileName)); } catch (FileNotFoundException e) { System.out.println("Could not open file " + fileName + ". Exiting program."); System.exit(-1); } // discard the headers s.nextLine(); while (s.hasNext()) { // discard the first four columns? s.next(); s.next(); s.next(); s.next(); // read the salary and name double salary = s.nextDouble(); String name = s.next(); totalSalary += salary; Person p = new Person(name, salary); if (highest == null) highest = p; else { if (p.salary > highest.salary) highest = p; } if (lowest == null) lowest = p; else { if (p.salaryRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.