Question: Java Question Write a program to prompt the user for 2 dates consisting of a month and a year and display the number of years

Java Question

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.

Java Question Write a program to prompt the user for 2 dates

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. Must have if else structure.

The input must be shown like this :

consisting of a month and a year and display the number of

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. b. Subtract the earlier year from the later year to get the year difference Subtract the month associated with the earlier year t from the month associated with the later vear The month difference can be negative (see examples in the table below). No. Dates Real Date Difference These dates are 12 years and 5 months apart These dates are 2 years and 10 months apart These dates are 3 years and 0 months apart These dates are 0 years and 4 months apart These dates are 0 years and 0 months apart Subtracting months and years August, 2011 March,1999 June, 1999 April, 2002 July, 1998 July, 1995 March, 1995 July, 1995 December, 1998 December, 1998 12 years and 5 month:s 3 years and -2 months 3 years and 0 months 0 year and 4 months 0 year and 0 month 2 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( 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(

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!