Table queries
The courses have launched and students have enrolled—well done! Your final task is to identify high-performing students who recently enrolled and are excelling in their studies to feature in your next campaign. You'll now work with a different dataset, students.csv, which contains information on all students and their grades. The GPA column contains their grade, and the EnrollmentDate column is the date the student enrolled in the course.
The Table, Selection, and LocalDate classes have been imported for you.
Cet exercice fait partie du cours
Importing Data in Java
Instructions
- Create a
Selectionfor"GPA"greater than3.5. - Create a
Selectionfor enrollment afterJan 1, 2022. - Combine both
Selectionobjects. - Filter the students table.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
public class StudentAnalysis {
public static void main(String[] args) {
try {
Table students = Table.read().csv("students.csv");
// Create a Selection for GPA greater than 3.5
Selection highGpa = students.doubleColumn("____").____(3.5);
// Create a Selection for enrollment after Jan 1, 2022
Selection freshmen = students.dateColumn("EnrollmentDate")
.____(LocalDate.of(2022, 1, 1));
// Combine both Selections
Selection highPerformingFreshmen = highGpa.____(freshmen);
// Filter the students table
Table featured = students.____(highPerformingFreshmen);
System.out.println("High-performing freshmen:");
System.out.println(featured.print());
} catch (Exception e) {
System.err.println("Error reading CSV files: " + e.getMessage());
}
}
}