Class Date

This composition example contains classes Date (Fig. F.7), Employee (Fig. F.8) and EmployeeTest (Fig. F.9). Class Date (Fig. F.7) declares instance variables month, day and year (lines 6–8) to represent a date. The constructor receives three int parameters. Line 17 invokes utility method checkMonth (lines 26–32) to validate the month—if the value is out of range the method throws an exception. Line 15 assumes that the value for year is correct and doesn’t validate it. Line 19 invokes utility method checkDay (lines 35–48) to validate the day based on the current month and year. Line 38 determines whether the day is correct based on the number of days in the particular month. If the day is not correct, lines 42–43 determine whether the ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.