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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education