Complete the missing sections to make the program work prope

Complete the missing sections to make the program work properly. You should complete each part that is marked with *-* in the comment. At the end of the main routine there is an output statement that indicates that the dates were invalid or were entered in the wrong order.

\"The dates were entered in the wrong order\" or

\"The one or both of the day values were invalid\" or

\"The one or both of the month values were invalid\" or

\"The one or both of the year values were invalid\"

here is the code===============

Solution

Please find the updatedd code,

package lab4part1f16;
import javax.swing.JOptionPane;
public class Lab4Part1F16
{
public static void main(String[] args)
{
boolean dayValid = true;
boolean monthValid = true;
boolean yearValid = true;

String input1 = JOptionPane.showInputDialog(
\" Enter a date value after January 1, 1600 and before the year \"
+ \"10000.\ Enter the date as one integer representing month \"
+ \"then day then year.\ Use two digits for day and month and four \"
+ \"digits for year\ filling with 0 as needed for the \"
+ \"month and day \ in the format MMDDYYYY: \");
int mmddyyyy1 = Integer.parseInt(input1);

String input2 = JOptionPane.showInputDialog(
\"Enter a second date value that is later than your previous date \"
+ \"\ in the same format MMDDYYYY: \");
int mmddyyyy2 = Integer.parseInt(input2);

System.out.println(\"date1 is \"+mmddyyyy1+\" date2 is \"+mmddyyyy2);

int mm1 = // *-* find the month value from mmddyyyy1
int dd1 = // *-* find the day
int yyyy1 = // *-* find the year
int mm2 = // *-* find the month value from mmddyyyy2
int yyyy2 = // *-* find the day
int dd2 = // *-* find the year

System.out.println(\"dd1 is \"+dd1+\" mm1 is \"+mm1 + \" yyyy1 is \"+yyyy1);
System.out.println(\"dd2 is \"+dd2+\" mm2 is \"+mm2 + \" yyyy2 is \"+yyyy2);

  
// For purposes of this validation, validate that no day value
// is greater than 31
dayValid = // *-* Use test conditions and logical operators to validate dd1
monthValid = // *-* Validate the month mm1
yearValid = // *-* Validate yyyy1 using the instructions given to the user
dayValid = dayValid && // *-* continue by validating dd2
monthValid = // *-* validate mm2 along with mm1
yearValid = // *-* valiate yyyy2 along with yyyy1

int daysBetween = 0;
int monthsBetween = 0;
int monthsCheck = 0;

int yearDiff = yyyy2 - yyyy1; // Number of years between dates
/*
Calculate number of days between the two dates by:
Finding the number of days until Dec 31 or day2 whichever comes first
algorithm = num days in mm1 - dd1 plus each month count from mm1+1 to Dec or mm2
Finding the number of days from Jan 1 to day2 if day1 and day2 in diff years
algorithm = month count from Jan to mm2-1 plus dd2
Adding days times number of years for intervening years
*/

if (yearDiff == 0) // Both dates in same year
{
monthsBetween = mm2 - mm1; // if year is same, day2 must be after day1
if (monthValid && (monthsBetween == 0))
{
daysBetween = dd2 - dd1;
}
else if (monthValid)
{
daysBetween = daysToEndOfMonth(dd1,mm1);
daysBetween = daysOfMonth(daysBetween, mm1+1, mm2);
daysBetween += dd2;
}
}
else if ((yearDiff > 0) && (monthValid)) // Year2 is after Year 1
{
System.out.println();
daysBetween = daysToEndOfMonth(dd1,mm1);
daysBetween = daysOfMonth(daysBetween,mm1+1,12+1);
daysBetween = daysOfMonth(daysBetween,1,mm2);
daysBetween += dd2;
daysBetween += // *-* add in 365 days for each year inbetween yyyy1 and yyyy2
}
String date1 = mm1+\"/\"+dd1+\"/\"+yyyy1;
String date2 = mm2+\"/\"+dd2+\"/\"+yyyy2;
  
if (((yearDiff >= 0) && yearValid) && (monthValid && dayValid))
{
System.out.println(\"The number of days between \"+date1
+\" and \"+date2+\" is \"+daysBetween);
}
else // <> check for question 1.b regarding more detailed error output
{
System.out.println(\"The dates were invalid or were entered in the wrong order\");
}
}
  
public static int daysToEndOfMonth(int dd, int mm)
{
int daysToEnd = 0;
switch(mm)
{
case 4:
case 6:
case 9:
case 11: daysToEnd = 30 - dd;
break;
/*
*-* Fill in the cases and actions for the remaining months
*/
}
return daysToEnd;
}
public static int daysOfMonth(int days, int m1, int m2)
{
while (m1 < m2)
{
if // *-* write the missing test conditions
{
// *-* fill in the missing action
}
else if (m1 == 2)
{
days = days + 28;
}
else
{
days = days + 31;
}
m1++;
}
return days;
}
  
}

Complete the missing sections to make the program work properly. You should complete each part that is marked with *-* in the comment. At the end of the main ro
Complete the missing sections to make the program work properly. You should complete each part that is marked with *-* in the comment. At the end of the main ro
Complete the missing sections to make the program work properly. You should complete each part that is marked with *-* in the comment. At the end of the main ro

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site