Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java compiler requires all local variables are initialized all the time before they can be used. In this project, in addition to storing first month

image text in transcribed

Java compiler requires all local variables are initialized all the time before they can be used. In this project, in addition to storing first month and second month as strings, you will need two variables to store the two months as int values so that months can be subtracted. For Example,

int firstMonthNumber, secongMonthNumber;

These two variables will be changed to numbers corresponding to the months users enter. For example,

if( firstMonth.equalIgnoreCase(January){ firstMonthNumber =1;}

Because the assignment is a conditional statement, firstMonthNumber is initialized conditionally. And then Java compiler will complain that variable firstMonthNumber may not have been initialized. To fix this, initialize firstMonthNumber to be 0, a default int value. For example,

int firstMonthNumber =0;

iles to be submitte . 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, Subtract the earlier year from the later year to get the year difference. Subtract the month associated with the earlier year from the month associated with the later year a. b. 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 ril, 2002 July, 1998 July, 1995 March, 1995 July, 1995 5 December, 1998 December, 1998 12 years and 5 months 3 years and -2 months 3 years and 0 months 0 year and 4 months 0 year and 0 month 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

How are master franchisees incorporated into the site?

Answered: 1 week ago

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago

Question

Describe how to measure the quality of work life.

Answered: 1 week ago