BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Importing Data in Java

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

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

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

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.____(____));
        
    }
}
Kodu Düzenle ve Çalıştır