Question: Write a class named, Date, to store a date: month, day and year. Each of these should be stored as an integer. The class should
Write a class named, Date, to store a date: month, day and year. Each of these should be stored as an integer. The class should contain all of the following public constructors and methods. These methods should have the EXACT same signature (method name and formal parameter list) and return type as given below. Be careful NOT to change the anything about the signatures and return types. In other words: DO NOT change anything about the signatures and return types as given below! This Date class you will write will be used as a new data type to create Date objects in other clients. A client is simply an application that uses a particular class. The Date class should contain no input or output statements whatsoever once it is submitted for grading. A client of the Date class would be responsible for doing its own input and/or output. Your instructor has a client that uses the Date class and all of its methods. This client is used to test your submitted Date.java. You will want to write your own application (client) that uses your Date class so that you can test your implementation of the Date class described below. Store your Date class client as a separate Java application in the same folder as your Date.java. To test Date.java include in your client statements to create Date objects, print Date objects, and invoke all of the other methods you implement in your Date class. Do not submit this client as it is only for your own testing. Submit only Date.java. Your instructor will expect it to compile and be usable by his own client in all the ways (methods) described below.
There are only two parts to this coding assignment I really do not understand:
public void addDays(int amt):
Change the current date by adding the number of days in the formal parameter. The value of the parameter could be positive or negative: a negative value results in making the date an earlier date. Examples: Adding 30 days to JAN-01-2000 gives JAN-31-2000 Adding 366 days to JAN-01-2000 gives JAN-01-2001 Adding -366 days to JAN-01-2000 gives DEC-31-1998 Adding -1000 days to JAN-01-2000 gives APR-06-1997
public int getDaysApart( Date other ):
Returns the difference between two dates in number of days. The retuned value is always a positive value. Examples: Days between JAN-01-2000 and JAN-01-2000 = 0 Days between JAN-01-2000 and JAN-11-2000 = 10 Days between JAN-01-2000 and APR-10-2000 = 100 Days between JAN-01-2000 and JUL-19-2000 = 200 Days between JAN-01-2000 and DEC-31-2000 = 365 Days between JAN-01-2000 and SEP-27-2002 = 1000
Could anyone help with these two aspects?
***We are not allowed to use any Calendar or existing Date java functions in the answer***
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
