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 |
Este exercício faz parte do curso
Cleaning Data in Java
Instruções do exercício
- Get the minimum and maximum of
quantities
. - Define ranges for low and high sales quantities.
- Check if the
quantity
is in the low range. - Check if the
quantity
is in the high range.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.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");
}
}
}
}