CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Importing Data in Java

Afficher le cours

Instructions

  • 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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

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);
    }
}
Modifier et exécuter le code