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.
Deze oefening maakt deel uit van de cursus
Cleaning Data in Java
Oefeninstructies
- 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.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
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");
}
}
}
}