Question: create a Date class of your own whose objects represent calendar dates, and turn in Date.java and TestDate.java onto the blackboard. You can test your
create a Date class of your own whose objects represent calendar dates, and turn in Date.java and TestDate.java onto the blackboard. You can test your Date class by creating a program (you could call it something like TestDate) that uses your Date instead of TeacherDate, within your test program you need to call required methods list below. Your Date class should implement the following behavior. None of the methods below should print any output to the console. You may not call any methods or utilize any behavior from the TeacherDate class to help implement your Date class, nor use any of Java's date-related objects such as GregorianCalendar.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);Or, rather than the above complicated expression, you may call the method TeacherDate.getDaysSinceEpoch() to see how many days have elapsed since 1/1/1970. (This is the ONLY place where your Date code may refer to TeacherDate.) int daysSinceEpoch = TeacherDate.getDaysSinceEpoch();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"Stylistic Guidelines:In your Date class, you should use at least one global constant in your program, to avoid "magic numbers." The choice of what constant to use is up to you, but it should represent an important value that is used in your class.You should properly encapsulate your Date objects by making sure that their methods and constructors are public and their data fields are private.Follow general stylistic guidelines from past assignments, such as indentation and whitespace, meaningful identifier names, and localization of variables.Include a comment at the beginning of your program with basic information and a description of the program and include a comment at the start of each method. Also put brief comments inside longer methods explaining the more complex sections of code.Hints and Suggestions:Write the Date(year,month,day) constructor, getDay, getMonth, getYear, toString methods first.Then implement isLeapYear.Next, try to write nextDay. (You may wish to write a helping method that returns the number of days in this Date's month, to help you implement nextDay.)Lastly, write getDayOfWeek and the Date() 'today' constructor. You can use your nextDay method to help you write these methods
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
