開始使用免費開始

驗證數值範圍

身為一家電玩發行商的資料分析師,你需要驗證整個遊戲目錄的銷售資料。電玩銷量可能差異很大,無效的資料會誤導關於該開發或推廣哪些遊戲的策略決策。藉由實作範圍驗證,你可以快速找出可疑的銷售數字,這些數字可能代表資料輸入錯誤。下面是你從電玩資料集中擷取的銷售數量樣本。請在這些資料上設定範圍檢查。

Game Platform Release date Quantity (millions of units)
Wii Sports Wii 11/19/2006 41.49
Super Mario Bros. NES 11/13/1985 29.08
Mario Kart Wii Wii 4/10/2008 15.85

所需的套件,例如 RangeCollections,都已為你匯入。

本練習屬於課程

使用 Java 進行資料清理

檢視課程

練習說明

  • 取得 quantities 的最小值與最大值。
  • 定義低與高銷售數量的範圍。
  • 檢查 quantity 是否落在低範圍內。
  • 檢查 quantity 是否落在高範圍內。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

public class RangeValidation {
    public static void main(String[] args) {
        List quantities = Arrays.asList(41.49, 29.08, 15.85);

        // Get the minimum and maximum quantities
        Double minQuantity = ____.____(quantities);
        Double maxQuantity = ____.____(quantities);

        System.out.println("Quantity range: " + minQuantity + " - " + maxQuantity);

        // Define ranges for low and high quantities
        Range lowQuantities = ____.____(0.0, 25.0);
        Range highQuantities = ____.____(25.0, 50.0);

        for (Double quantity : quantities) {
            // Check if the quantity is low
            if (____.____(quantity)) {
                System.out.println(quantity + " - Low quantity");
            // Check if the quantity is high
            } else if (____.____(quantity)) {
                System.out.println(quantity + " - High quantity");
            } else {
                System.out.println(quantity + " - Out of expected range");
            }
        }
    }
}
編輯並執行程式碼