Get startedGet started for free

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.

This exercise is part of the course

Importing Data in Java

View Course

Exercise instructions

  • Create a Selection for "GPA" greater than 3.5.
  • Create a Selection for enrollment after Jan 1, 2022.
  • Combine both Selection objects.
  • Filter the students table.

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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());
        }
    }
}
Edit and Run Code