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.
Bu egzersiz, kursun bir parçasıdır
Importing Data in Java
Egzersiz talimatları
- 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.
Uygulamalı etkileşimli egzersiz
Bu egzersizi bu örnek kodu tamamlayarak deneyin.
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);
}
}