Validating numeric ranges
As a data analyst at a video game publisher, you need to validate sales data across your game catalog. Video game sales can vary dramatically. Invalid data could mislead strategic decisions about which games to develop or promote. By implementing range validation, you can quickly identify suspicious sales figures that might indicate data entry errors. You've extracted sample sales quantities from a video game dataset below. Set up range checks on this data.
| 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 |
The necessary packages such as Range, and Collections have been imported for you.
이 연습은 강의의 일부입니다
Cleaning Data in Java
연습 안내
- Get the minimum and maximum of
quantities. - Define ranges for low and high sales quantities.
- Check if the
quantityis in the low range. - Check if the
quantityis in the high range.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
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");
}
}
}
}