QuestionQuestion

Write Date.java and Difference.java -- a program that prompts the user for a pair of dates and their description. The main program is in Difference.java and Date.java contains a Date class. The Date class must contain the following methods:

public Date(int year, int month, int day, String desc)
Constructs a new Date object to represent the given Date.

public int daysTo(Date other)
Returns the number of days that this date must be adjusted to make it equal to the other Date.

public int monthsTo(Date other)
Returns the number of months that this date must be adjusted to make it equal to the other Date.

public int yearsTo(Date other)
Returns the number of years that this date must be adjusted to make it equal to the other Date.

public int getDay()
returns the value of this Date; for example 2011/4/2 returns 2

public int getMonth()
returns the value of this Date; for example 2011/4/2 returns 4

public int getYear()
returns the value of this Date; for example 2011/4/2 returns 2011

public String getDesc()
returns the value of this Date’s description

public int compareTo(Date other)
returns -1 if this date is less than the other date; returns 0 if they are the same date; returns 1 if this date is greater than the other date.

public boolean isLeapYear()
returns the true if this date is a leap year. A leap year occurs every four years, except for multiples of 100 that are not multiples of 400. For example, 1956, 1844, 1600 and 2000 are leap
years, but 1983, 2002, 1700 and 1900 are not

public String toString()
returns a String representation of this date in year/month and day order; for example 2011/4/2 returns “2011/04/02”

The above descriptions of the methods should be copied as comments in each method.

Make your program's output look exactly (character for character) as is shown. Use functions.

Program asks you for a pair of dates and their description. It calculates the number of years, months and days between the two dates.

Enter the first date (or just 0 to stop): 2006/2/23 Begin date Enter the second date (or just 0 to stop): 2006/2/28 End date

There are 0 year(s) 0 month(s) 5 day(s) between Begin date (02/23/2006) and End date (02/28/2006)

Enter the first date (or just 0 to stop): 1948/10/31 Birthdate Enter the second date (or just 0 to stop): 2016/3/29 Todays date

There are 67 year(s) 4 month(s) 29 day(s) between Birthdate (10/31/1948) and Todays date (03/29/2016)

Enter the first date (or just 0 to stop): 1948/10/31 Birthdate
Enter the second date (or just 0 to stop): 1776/7/4 First Independence Day Birthdate (10/31/1948) occurs after First Independence Day (07/04/1776) Enter the first date (or just 0 to stop): 0
This program must have a makefile in the same directory.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Date {

private int day;
private int month;
private int year;
private String desc;

public Date(int y, int m, int d, String dsc) {
year = y;
month = m;
day = d;
desc = dsc;
}

public int yearsTo(Date other) {
int otherDay = other.getDay();
int otherMonth = other.getMonth();
int otherYear = other.getYear();
if(this.year < otherYear) {
if(this.month < otherMonth)
return otherYear - this.year;
else if(this.month > otherMonth)
return otherYear - this.year - 1;
}
else if(this.year > otherYear) {
if(this.month < otherMonth)
return this.year - otherYear - 1;
else if(this.month > otherMonth)
return this.year - otherYear;
}
return 0;
}

public int monthsTo(Date other) {
int otherDay = other.getDay();
int otherMonth = other.getMonth();;
if(this.month < otherMonth) {
if(this.day <= otherDay)
return otherMonth - this.month;
else
return otherMonth - this.month - 1;
}...
$25.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats