Department summary statistics
For the executive summary, HR requires aggregate statistics including total payroll, average salary, and the highest salary. You'll need to combine all salary values into single summary figures.
The Tablesaw library has been imported, and employees.csv contains the salary data.
Diese Übung ist Teil des Kurses
Importing Data in Java
Anleitung zur Übung
- Aggregate all salaries to calculate the total payroll.
- Compute the average salary using the total and row count.
- Find the highest salary in the dataset.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
public class DepartmentSummaryStats {
public static void main(String[] args) {
Table employees = Table.read().csv("employees.csv");
DoubleColumn salaryCol = employees.intColumn("Salary").asDoubleColumn();
// Aggregate salaries for total payroll
double totalPayroll = salaryCol.____(0.0, Double::____);
// Compute average salary
double avgSalary = totalPayroll / employees.____();
// Find highest salary
double maxSalary = salaryCol.reduce(0.0, Double::____);
System.out.println("Department Summary Statistics:");
System.out.println("=================================");
System.out.println("Total Employees: " + employees.rowCount());
System.out.println("Total Payroll: $" + totalPayroll);
System.out.println("Average Salary: $" + avgSalary);
System.out.println("Highest Salary: $" + maxSalary);
}
}