View the step-by-step solution to:

Design a class named MyDate. The class contains : The data fields year, month, and day that represesents a date. month is 0-based, i., 0 is January.

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.

Top Answer

package mani; import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class MyDate{ int year; int... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online