LoslegenKostenlos loslegen

Modifying table structure

The meteorological station now needs to update its weather data table to accommodate new temperature forecasts. They want to add forecast temperatures while keeping the actual recorded temperatures for comparison purposes.

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

Diese Übung ist Teil des Kurses

Importing Data in Java

Kurs anzeigen

Anleitung zur Übung

  • Rename the "Temperature" column to "ActualTemp".
  • Add a new "ForecastTemp" column to the table.
  • Print the table structure.
  • Print the first three rows.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

public class ModifyWeatherTable {
    public static void main(String[] args) {
        StringColumn days = StringColumn.create("Day", 
            "Monday", "Tuesday", "Wednesday");
            
        DoubleColumn temperatures = DoubleColumn.create("Temperature", 
            22.5, 24.0, 23.2);
            
        DoubleColumn precipitation = DoubleColumn.create("Precipitation", 
            0.0, 2.5, 5.2);
            
        Table weatherData = Table.create("WeatherData")
            .addColumns(days, temperatures, precipitation);
        
        // Rename the Temperature column
        weatherData.____("Temperature").____("____");
        
        // Add a new ForecastTemp column
        DoubleColumn forecastTemps = DoubleColumn.create("ForecastTemp", 
            23.0, 25.2, 22.8);
        weatherData = weatherData.____(forecastTemps);
        
        // Print the table structure
        System.out.println(weatherData.____());
        
        // Print the first three rows
        System.out.println(weatherData.____(____));
        
    }
}
Code bearbeiten und ausführen