Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Practice with defining new types of objects. This assignment asks you to create a Date class whose objects represent calendar dates. Methods you must implement

Practice with defining new types of objects. This assignment asks you to create a Date class whose objects represent calendar dates.

Methods you must implement in your Date class (these methods are also already present in the TeacherDate class):

public Date(int year, int month, int day) Constructs a new Date representing the given year, month, and day. You may assume that the parameter values are valid. Since the modern Gregorian calendar was established in late 1752, you may assume that the year parameter value will be greater than or equal to 1753.

public Date() Constructs a new Date representing today (the date at which the program is run).

It may be helpful for you to know that the following expression returns the number of days that have elapsed since January 1, 1970. (You must import java.util.*; to be able to refer to TimeZone.)

int daysSinceEpoch = (int) ((System.currentTimeMillis() + TimeZone.getDefault().getRawOffset()) / 1000 / 60 / 60 / 24);

public int getDay()

Returns this Date's day of the month, between 1 and the number of days in that month (which will be between 28 and 31).

public int getMonth() Returns this Date's month of the year, between 1 and 12.

public int getYear() Returns this Date's year.

public String getDayOfWeek() Returns a String representing what day of the week this Date falls on. The String will be either "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", or "Saturday". For example, August 7, 2005 fell on a Sunday, so the return value for a new Date(2005, 8, 7) object would be "Sunday".

It may be helpful for you to know that January 1, 1753 was a Monday.

public boolean isLeapYear() Returns whether this Date's year is a leap year. Leap years are all years that are divisible by 4, except for years that are divisible by 100 but not by 400. For example, 1756, 1952, 2004, 1600, and 2000 are all leap years, but 1753, 2005, 1700, and 1900 are not.

public void nextDay() Advances this Date to the next day after its current day. Note that this might advance the Date into the next month or year. For example, the next day after August 7 is August 8; the next day after December 31 is January 1; the next day after February 28, 2005 is March 1, 2005, and the next day after February 28, 2004 is February 29, 2004 (because 2004 is a leap year).

public String toString() Returns a String representation of this Date, in a year/month/day format to match the following: "2005/5/24"

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

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions