MulaiMulai sekarang secara gratis

Penyaringan tabel

Sekarang setelah Anda memuat katalog produk dasar, startup ingin berfokus pada produk premium untuk kursus pelatihan lanjutan mereka. Anda perlu mengidentifikasi produk mana yang dianggap "premium" (berharga di atas $800) dan membuat himpunan data tersaring untuk tim pemasaran.

Kelas Table, DoubleColumn, dan Selection telah diimpor untuk Anda.

Latihan ini adalah bagian dari kursus

Mengimpor Data di Java

Lihat Kursus

Petunjuk latihan

  • Buat Selection untuk "Price" yang lebih besar dari 800.
  • Saring tabel produk menggunakan Selection.
  • Cetak jumlah baris produk premium.
  • Cetak harga rata-rata produk premium.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

public class ProductCatalog {
    public static void main(String[] args) {
    	try {
        	Table products = Table.read().csv("products.csv");

        	// Create a Selection for Price greater than 800
        	Selection premiumSelection = products.doubleColumn("Price")
            	.____(____);

        	// Filter the products table using the Selection
        	Table premiumProducts = products.____(____);

        	// Print the row count of premium products
        	System.out.println("Number of premium products: " + premiumProducts.____());

        	// Print the mean price of premium products
        	DoubleColumn premiumPrices = premiumProducts.doubleColumn("Price");
        	System.out.println("Average price of premium products: $" + premiumPrices.____());
		} catch (Exception e) {
            System.err.println("Error reading CSV files: " + e.getMessage());
		}
    }
}
Edit dan Jalankan Kode