LoslegenKostenlos loslegen

Working with column types

You're building a product catalog for a tech training startup. Before creating courses, you need to analyze the product pricing-understanding the price range helps determine which products to prioritize. Working with typed columns like DoubleColumn gives you access to statistical methods that generic columns don't provide.

The Table and DoubleColumn classes have been imported for you.

Diese Übung ist Teil des Kurses

Importing Data in Java

Kurs anzeigen

Anleitung zur Übung

  • Read "products.csv" into the products table.
  • Access the "Price" column and store it in prices.
  • Print the mean price.

Interaktive Übung

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

public class ProductCatalog {
    public static void main(String[] args) {
    	try {
          // Load products.csv into the products table
          Table products = Table.____().csv("____");

		  // Access the Price column and store it in prices
          DoubleColumn ____ = products.doubleColumn("____");
          
          // Print the mean price
          System.out.println("Price Stats - Min: $" + prices.min() +
                  ", Max: $" + prices.max() +
                  ", Mean: $" + prices.____());

          System.out.println(products.first(5));
        } catch (Exception e) {
            System.err.println("Error reading CSV files: " + e.getMessage());
        }
    }
}
Code bearbeiten und ausführen