Design a class named mydate the class contains the data


Design a class named MyDate. The class contains :

• The data fields year, month, and day that represesents a date. month is 0-based, i.e., 0 is January.

• A no-arg constructor that creates a MyDate object for the current date.

• A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds.

• A constructor that constructs a MyDate object with the specified year, month, and day.

• Three get and set methods for the data fields year, month and day respectively. Write a test program that creates two MyDate objects (using new MyDate() and new MyDate( 3435555533101L) and displays their year, month and day. Hint : you can use any pre-defined class like GregorianCalendar to simplify coding:

• Java API has the GregorianCalender class in the java.util package, which you can use to obtain year, month and day of a date.

• The no-arg constructor constructs an instance of the current date and the methods get(GregorianCalendar.YEAR), get(GregorianCalendar.MONTH), and get(GregorainCalendar.Day_OF_MONTH) return the year, month and day.

• The GregorianCalendar class has setTimeInMillis(long), which can be used to set a specified time since January 1, 1970.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Design a class named mydate the class contains the data
Reference No:- TGS01525056

Now Priced at $15 (50% Discount)

Recommended (94%)

Rated (4.6/5)