BaşlayınÜcretsiz Başlayın

Annotations with video game sales

You want to validate video game sales to detect any mistakes in the data. Some sample data is shown below. Set up the VideoGameSale class attributes with annotations to check for empty fields and verify that fields meet certain values.

name platform year sales
Wii Sports Wii 2006 41.49
Super Mario Bros. NES 1985 29.08
Mario Kart Wii Wii 2008 15.85

jakarta.validation.constraints package has been imported for you.

Bu egzersiz

Cleaning Data in Java

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Add annotations to check that name and platform are not empty.
  • Check that year is at least 1960.
  • Verify that sales is positive.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

public class VideoGameSale {
    // Check that name is not empty
    @____(message = "Name cannot be empty")
    private String name;

    // Check that platform is not empty
    @____(message = "Platform cannot be empty")
    private String platform;

    // Check that year is at least 1960
    ____(value = ____, message = "Year must be greater than 1960")
    private Integer year;

    // Check that sales is positive
    ____(value = ____, message = "Sales amount must be positive")
    private Double sales;
    
    public static void main(String[] args) {
        System.out.println("Nice job setting up the annotations!");
    }
}
Kodu Düzenle ve Çalıştır