You will create a Java class named Date that is used to work with date operations. Then you will write a Driver to test each method you wrote in the Dare class and display, on the screen, a clear explanation and result of each test.
For documentation, use inline comments AND javadoc comments above each class and above each method. Use the tags : @author, @version, @param, @return
Mandatory methods for the Date class:
- At least three constructor methods, including the default constructor and the copy constructor.
- A toString( ) method.
- An equals( ) method.
- A compareTo( ) method.
- an add( ) method that adds an integer number of days to an existing Date and returns the new Date object:
Date myDate = new Date(3, 20, 2014);
Date result;
result = Date.add(15);
System.out.println(result);
- A subtract( ) method that subtracts an integer number of days from an exisiting Date and returns a new Date object.
Date myDate = new Date(3, 20, 2014);
Date result;
result = myDate.subtract(5);
System.out.println(result);
A dateDiff( ) methods that calculates and returns the number of days between the parameters and the Date object.
Date dateOne = new Date(3,15, 2014);
Date dateTwo = new Date(4, 18, 2014);
int difference;
difference = dateOne.difference(dateTwo);
System.out.println("the difference between " + dateOne + " and " + dateTwo + " is" + difference + " days");
The code must take into account leap year and adding or subtracting between years. Write two additional methods that you come with on your own as well.