Modify the Date class below by adding a new method called nextDay() that increments the Date by 1 when called and returns a new Date object. This method should properly increment the Date across Month boundary (i.e from the last day of the month to the first day of the next month). //Date class declaration public class Date { private int month; // 1-12 private int day; // 1-31 based on month private int year; // any year private static final int [] daysPerMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //constructor: confirm proper value for month and day given the year public Date (int month, int day, int year) { //check if month in range if (month <=0 II month > 12) { throw new IllegalArgumentException( “month (“ + month + “) must be 1-12”); } //check if day in range for month if (day <= 0 II (day > daysPerMonth[month] && ! (month == 2 && day == 29))) { Throw new IllegalArgumentException(”day (“ + day + “) out-of-range for the specified month and year”); } //check for leap year if month is 2 and day is 29 if (month == 2 && day == 29 && !(year % 400 ==0 II (year % 4 == 0 && year % 100 ! = 0 ))) { throw new IllegalArgumentException(“day (“ + day + “) out-of-range for the specified month and year”); } this.month = month; this.day = day; this.year = year; System.out.printf(“Date object constructor for date %s%n”, this); } //return a String of the form month/day/year public String toString() { return String.format(“%d/%d/%d”, month, day, year): } } Write a program called DateTest that asks the user to enter 3 numbers (one at a time) corresponding to Month, Day and Year. The first two will be 2 digits(Month and Day) and 3rd will be 4 digits(Year). Read the numbers and create a corresponding Date object. Write a loop that increments this Date 3 times by calling nextDay()and displays each Date in the format mm/dd/yyyy on the console. You MUST use nextDay() to generate the dates. You CANNOT HARD CODE the output. Your program should work for any valid data that user enters. (Assume that the user will enter VALID month,day and year numbers). You can assume that all dates will be in the same year 2020. Example: If user enters 07 30 and 2020. The following should be displayed: 07/30/2020 07/31/2020 08/01/2020 Upload 2 Java files: Date.java and DateTest.java.
Modify the Date class below by adding a new method called nextDay() that increments the Date by 1 when called and returns a new Date object. This method should properly increment the Date across Month boundary (i.e from the last day of the month to the first day of the next month).
//Date class declaration
public class Date {
private int month; // 1-12
private int day; // 1-31 based on month
private int year; // any year
private static final int [] daysPerMonth =
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//constructor: confirm proper value for month and day given the year
public Date (int month, int day, int year) {
//check if month in range
if (month <=0 II month > 12) {
throw new IllegalArgumentException(
“month (“ + month + “) must be 1-12”);
}
//check if day in range for month
if (day <= 0 II
(day > daysPerMonth[month] && ! (month == 2 && day == 29))) {
Throw new IllegalArgumentException(”day (“ + day +
“) out-of-range for the specified month and year”);
}
//check for leap year if month is 2 and day is 29
if (month == 2 && day == 29 && !(year % 400 ==0 II
(year % 4 == 0 && year % 100 ! = 0 ))) {
throw new IllegalArgumentException(“day (“ + day +
“) out-of-range for the specified month and year”);
}
this.month = month;
this.day = day;
this.year = year;
System.out.printf(“Date object constructor for date %s%n”, this);
}
//return a String of the form month/day/year
public String toString() {
return String.format(“%d/%d/%d”, month, day, year):
}
}
Write a program called DateTest that asks the user to enter 3 numbers (one at a time) corresponding to Month, Day and Year. The first two will be 2 digits(Month and Day) and 3rd will be 4 digits(Year). Read the numbers and create a corresponding Date object. Write a loop that increments this Date 3 times by calling nextDay()and displays each Date in the format mm/dd/yyyy on the console. You MUST use nextDay() to generate the dates. You CANNOT HARD CODE the output.
Your program should work for any valid data that user enters. (Assume that the user will enter VALID month,day and year numbers).
You can assume that all dates will be in the same year 2020.
Example:
If user enters 07 30 and 2020. The following should be displayed:
07/30/2020
07/31/2020
08/01/2020
Upload 2 Java files: Date.java and DateTest.java.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps