Get startedGet started for free

Creating a table

A local weather station in New York needs to track daily temperature readings for a weekly report during an unusual heat wave. The station manager has asked you to create a simple data structure that can be used to generate statistics and visualizations for their weekly climate briefing. The table should help meteorologists identify trends and anomalies in temperature and precipitation patterns.

The Table, DoubleColumn, and StringColumn classes from Tablesaw have been imported for you.

This exercise is part of the course

Importing Data in Java

View Course

Exercise instructions

  • Create three columns: day of week, temperature, and precipitation.
  • Create a table and add all columns to it.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

public class WeatherTableExample {
    public static void main(String[] args) {
        // Create three columns
        StringColumn days = ____.____("Day", 
            "Monday", "Tuesday", "Wednesday");
            
        DoubleColumn temperatures = ____.create("Temperature", 
            22.5, 24.0, 23.2);
            
        DoubleColumn precipitation = ____.create("Precipitation", 
            0.0, 2.5, 5.2);
        
        // Create a table and add all columns
        Table weatherData = Table.____("WeatherData")
            .____(____, ____, precipitation);
        
        System.out.println(weatherData);
    }
}
Edit and Run Code