Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA HELP - Use the following template: Rewrite the definitions of the method setDate and the constructor with parameters so that the values for the
JAVA HELP -
Use the following template:
Rewrite the definitions of the method setDate and the constructor with parameters so that the values for the month, day, and year are checked before storing the date into the data members.
Add a method member, isLeapYear, to check whether a year is a leap year.
Write a test program to test your class
public class Date { private int dMonth; //variable to store the month private int dDay; //variable to store the day private int dYear; //variable to store the year //Default constructor //Data members dMonth, dDay, and dYear are set to //the default values //Postcondition: dMonth = 1; dDay = 1; dYear = 1900; public Date() { dMonth = 1; dDay = 1; dYear = 1900; } //Constructor to set the date //Data members dMonth, dDay, and dYear are set //according to the parameters //Postcondition: dMonth = month; dDay = day; // dYear = year; // This constructor needs to be rewitten **************************** public Date(int month, int day, int year) { dMonth = month; dDay = day; dYear = year; } //Method to set the date //Data members dMonth, dDay, and dYear are set //according to the parameters //Postcondition: dMonth = month; dDay = day; // dYear = year; // This constructor needs to be rewitten **************************** public void setDate(int month, int day, int year) { dMonth = month; dDay = day; dYear = year; } //Method to return the month //Postcondition: The value of dMonth is returned public int getMonth() { return dMonth; } //Method to return the day //Postcondition: The value of dDay is returned public int getDay() { return dDay; } //Method to return the year //Postcondition: The value of dYear is returned public int getYear() { return dYear; } //Method to return the date in the form mm-dd-yyyy public String toString() { return (dMonth + "-" + dDay + "-" + dYear); } // This method checks whether a year is a leap year // Write the code for this method *********************************** public boolean isLeapYear() { } } |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started