वीडियो गेम बिक्री के साथ annotations
आप डेटा में किसी भी गलती का पता लगाने के लिए वीडियो गेम बिक्री को validate करना चाहते हैं. नीचे कुछ सैंपल डेटा दिया गया है. खाली फ़ील्ड्स की जाँच करने और यह सुनिश्चित करने के लिए कि फ़ील्ड्स कुछ निश्चित मानों को पूरा करें, VideoGameSale क्लास के attributes को annotations के साथ सेट अप कीजिए.
| 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 पैकेज को इम्पोर्ट किया गया है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Java में डेटा क्लीनिंग
अभ्यास निर्देश
- ऐसे annotations जोड़ें जो जाँचें कि
nameऔरplatformempty न हों. - जाँचें कि
yearकम-से-कम 1960 हो. - verify करें कि
salespositive हो.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
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!");
}
}