验证数值范围
作为一家电子游戏发行商的数据分析师,您需要验证整个游戏目录的销量数据。电子游戏销量差异可能很大。无效数据会误导关于开发或推广哪些游戏的战略决策。通过实现范围验证,您可以快速识别可疑的销量数字,从而发现可能的数据录入错误。下面是您从一个电子游戏数据集中抽取的销量样本。请为这些数据设置范围检查。
| 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 |
所需的包,例如 Range 和 Collections,已为您导入。
本练习是课程的一部分
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");
}
}
}
}