Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and

public class Date { private int month; private int day; private int year;

/** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); }

/** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy ) { setDate( mm, dd, yyyy ); }

/* accessor methods */ int getMonth( ) { return month; } int getDay( ) { return day; } int getYear( ) { return year; }

/** mutator method */ /** setDate * @param mm new value for month * @param dd new value for day * @param yyyy new value for year * passes parameters to setMonth, setDay, and setYear */ public void setDate( int mm, int dd, int yyyy ) { setYear(yyyy); setMonth( mm ); setDay( dd ); } /** helper methods */ /** setDay * @param dd new value for day * if dd is legal day for current month, sets day to dd * otherwise, sets day to 1 */ private void setDay( int dd ) { int [] validDays = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; day = ( dd >= 1 && dd <= validDays[month] ? dd : 1 ); } /** setMonth * @param mm new value for month * if mm is between 1 and 12, sets month to mm * otherwise, sets month to 1 */ private void setMonth( int mm ) { month = ( mm >= 1 && mm <= 12 ? mm : 1 ); } /** setYear * @param yyyy new value for year * sets year to yyyy */ private void setYear( int yyyy ) { year = yyyy; } /** toString * @return String * returns date in mm/dd/yyyy format */ public String toString( ) { return month + "/" + day + "/" + year; }

/** equals * @param d Date object to compare to this * @return true if d is equal to this * false, otherwise */ public boolean equals( Date d ) { if ( month == d.month && day == d.day && year == d.year ) return true; else return false; } }

We need to use this Data class to add to the DataClient class, which is

public class DateClient { public static void main( String [] args ) { // add code to construct Data objects // and test and output if they are a // leap year or not // not leap year (not divisible by 4)

// leap year (divisible by 4, but not by 100)

// not leap year (divisible by 4 and by 100)

// leap year (divisible by 4 and by 100 and by 400)

}

Below are the rules to determine if a year is a leap year.

  • Every year divisible by 4 is a leap year,

  • But every year divisible by 100 is NOT a leap year,

  • Unless the year is also divisible by 400, then it is still a leap year.

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

Step: 3

blur-text-image

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

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

A 300N F 30% d 2 m Answered: 1 week ago

Answered: 1 week ago