Answer:
Certainly! Here's an updated version of the Date class in Java, as per your requirements:
javaCopy code
public class Date { private int month; // 1-12 private int day; // 1-31 based on month private int year; // any year // constructor: confirm proper value for month and day given the year public Date(int month, int day, int year) { // validate month if (month < 1 || month > 12) { throw new IllegalArgumentException("Month must be between 1 and 12."); } // validate day int maxDay = getMaxDay(month, year); if (day < 1 || day > maxDay) { throw new IllegalArgumentException("Day must be between 1 and " + maxDay + " for the given month and year."); } this.month = month; this.day = day; this.year = year; } // helper method to determine the maximum day for a given month and year private int getMaxDay(int month, int year) { if (month == 2) { // February if (isLeapYear(year)) { return 29; } else { return 28; } } else if (month == 4 || month == 6 || month == 9 || month == 11) { return 30; } else { return 31; } } // helper method to check if a year is a leap year private boolean isLeapYear(int year) (year % 4 == 0 && year % 100 != 0); // increment the day by one