Aan de slagGa gratis aan de slag

Validating date ranges

You have validated the numeric ranges of the video game sales quantities. Now you need to validate the ranges of the video game release dates. The dates should fall between 1/1/1985 and 12/31/2024. Sample dates have been extracted from the dataset below. Set up date 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 LocalDate, and DateTimeFormatter have been imported for you.

Deze oefening maakt deel uit van de cursus

Cleaning Data in Java

Cursus bekijken

Oefeninstructies

  • Check that the release date occurs after startDate.
  • Verify that the release date is before endDate.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

public class RangeValidation {
    public static void main(String[] args) {
        List releaseDates = Arrays.asList("11/19/2006", "11/13/1985", "4/10/2008");

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d/yyyy");
        LocalDate startDate = LocalDate.of(1985, 1, 1);
        LocalDate endDate = LocalDate.of(2024, 12, 31);

        for (String dateStr : releaseDates) {
            LocalDate releaseDate = LocalDate.parse(dateStr, formatter);
            // Check that the release date occurs after startDate
            boolean isValid = ____.____(startDate)
                    // Verify that the release date is before endDate
                    && ____.____(endDate);
            System.out.println(dateStr + " is valid: " + isValid);
        }
    }
}
Code bewerken en uitvoeren