Solved by verified expert:Project 3 Decision Structures (Chapter 3) Files to be submitted: An algorithm – a regular text file Java Source code – a Java source file Supporting files if any Write a program to prompt the user for 2 dates consisting of a month and a year and display the number of years and months between these 2 dates. Either date could be the earlier date. It is REQUIRED to use the following solution to calculate the difference between two dates that are not in the same year: 1. To calculate a positive year difference and the corresponding month difference, a. Subtract the earlier year from the later year to get the year difference. b. Subtract the month associated with the earlier year from the month associated with the later year.I download the word file on the bottom.
project_3_decision_structures.docx

Unformatted Attachment Preview

Project 3 Decision Structures (Chapter 3)
Files to be submitted:
• An algorithm – a regular text file
• Java Source code – a Java source file
• Supporting files if any
Write a program to prompt the user for 2 dates consisting of a month and a year and display the number of years and
months between these 2 dates. Either date could be the earlier date.
It is REQUIRED to use the following solution to calculate the difference between two dates that are not in the same year:
1. To calculate a positive year difference and the corresponding month difference,
a. Subtract the earlier year from the later year to get the year difference.
b. Subtract the month associated with the earlier year from the month associated with the later year.
The month difference can be negative (see examples in the table below).
No.
Dates
Subtracting months and years
Real Date Difference
1
August, 2011
March, 1999
12 years and 5 months
These dates are 12 years and
5 months apart.
2
June,1999
April, 2002
3 years and -2 months
These dates are 2 years and
10 months apart.
3
July, 1998
July, 1995
3 years and 0 months
These dates are 3 years and 0
months apart.
4
March 1995
July, 1995
0 year and 4 months
These dates are 0 years and 4
months apart.
5
December 1998
December, 1998
0 year and 0 month
These dates are 0 years and 0
months apart.
In sample 2, the month difference is negative. The difference, 3 years and -2 months, means it would be 3-year difference if this
were 2 months later. A date difference should not contain a negative month difference. A negative can be adjusted by regrouping
one year difference into 12 month difference.
2. To calculate a date difference between two dates that are in the same year, the year difference is always zero. The month
difference should be calculated as a non-negative value.
Hint:
It is important to store the month as a String value and as an int value (1 for January, 2 for February …). The String value is used
for month checking; the int value is used for calculating a date difference.
if (firstMonth.equalsIgnoreCase(“January”)){
firstMonthNumber = 1;
} else if(firstMonth.equalsIgnoreCase(“February”)){
firstMonthNumber = 2;
}

else{

}
Sample Run 1:
For the first date,
Enter month: August
Enter year: 2011
For the second date,
Enter month: March
Enter year: 1999
These dates are 12 years and 5 months apart.
Sample Run 2:
For the first date,
Enter month: June
Enter year: 1999
For the second date,
Enter month: April
Enter year: 2002
These dates are 2 years and 10 months apart.
Sample Run 3:
For the first date,
Enter month: July
Enter year: 1998
For the second date,
Enter month: July
Enter year: 1995
These dates are 3 years and 0 months apart.
Sample Run 4:
For the first date,
Enter month: March
Enter year: 1995
For the second date,
Enter month: July
Enter year: 1995
These dates are 0 years and 4 months apart.
Sample Run 5:
For the first date,
Enter month: December
Enter year: 1998
For the second date,
Enter month: December
Enter year: 1998
These dates are 0 years and 0 months apart.

Purchase answer to see full
attachment