Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions

Question

What's the most daring thing you've ever done?

Answered: 1 week ago

Question

How does cultural context affect communication? [LO-6]

Answered: 1 week ago