Question: Write a Java program and JUnit4 test: Write a Java class CustomDate that represents a calendar date consisting of a month, day, and year. Use

Write a Java program and JUnit4 test:

Write a Java class CustomDate that represents a calendar date consisting of a month, day, and year. Use three data fields of type int to represent the date. For example, July 4, 1776, is month 7, day 4, and year 1776. There should be no other instance variables other than these three integer values.

  • Write both default and parameterized constructors the default date should be set to January 1, 1900.
  • Setter methods (setDay, setMonth, setYear) with one argument to change the day month or year (the month setter is overloaded one setter to accept an integer value and the other to accept a String representing the month);
  • Getter methods (getDay, getMonth, getYear) that return the day, month, or year as an int;
  • A toString method (public String toString()).
  • In addition, provide methods that
  • Determine whether the current year is a leap year (public boolean isLeapYear())
  • Advance the current date by one day (public void advanceOneDay())
  • Advance the current date by one week (public void advanceOneWeek())
  • Override the equals method from Object (public boolean equals(Object obj))
  • Compares this CustomDate object with the object passed as a parameter for chronological order and returns a negative integer, zero, or a positive integer, if this object is less than, equal to, or greater than the specified object. (public int compareTo (CustomDate obj) )

Write a class to test your class called CustomDateTest using JUnit4.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!