ComeçarComece de graça

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.

Este exercício faz parte do curso

Importing Data in Java

Ver curso

Instruções do exercício

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

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

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);
    }
}
Editar e executar o código