Question: package lab; import java.util.Scanner; public class lab { /** * Calculating your age from birthdate * @param args the command line arguments */ public static

package lab;

import java.util.Scanner;

public class lab

{ /**

* Calculating your age from birthdate

* @param args the command line arguments

*/

public static void main(String[] args)

{

int bday, bmonth, byear; // birth date

int cday, cmonth, cyear; // current date or date to check against

int age = -1;

Scanner input = new Scanner(System.in);

// Ask for user birthdate (assume the dates are valid)

System.out.println("Welcome to the age calculator that calculates the age in the "+

"American fashion, i.e. a baby turns 1 year old on the first anniversary of its birth.");

System.out.println(" Please enter your birthdate in the following format, MM DD YYYY, "+

"where MM is the number representing your birthmonth, DD is the "+

"number representing the day of your birth, and YYYY is the year "+

"of your birth. Leave blanks between the numbers.");

System.out.print("Birthdate MM DD YYYY : ");

bmonth = input.nextInt();

bday = input.nextInt();

byear = input.nextInt();

// Find out current date or date to check against (assume the dates are valid)

System.out.println(" Please enter the date for which you wish to find your age. This "+

"can be the current date to find a current age or to find your age "+

"as of some other date. Use the same format as for birthdate.");

System.out.print("Comparison date MM DD YYYY : ");

// Determine if age is after date by the following:

if (byear >= cyear) // dates are in same year

{

//System.out.println("DEBUG: in byear >= cyear");

if (bmonth > cmonth) // birth month in future

{

System.out.println(" The birthdate is in a future month.");

}

else if (bmonth == cmonth) // dates are in the same month

{

if (bday > cday) // birth day is in the future

{

System.out.println(" The birthdate is in this month in the future.");

}

else // birth in earlier in month

{ // Age is zero

}

}

else // birth in earlier in year

{ // Age is zero

}

}

// If month of birthdate is less than month of current date

else if (bmonth < cmonth)

{ // Age is current year - birth year

}

// Else if month of birthdate is greater than month of current date

// Age is current year - birth year - 1

// Else if day of birthdate is less than or equal to day of current date

// Age is current year - birth year (months are same)

// Else if day of birthdate is greater than day of current date

// Age is current year - birth year - 1

// Else

else

{ // Birthdate is in the future so there is no age

System.out.println(" The birthdate is in the future.");

}

// Output age

System.out.println(" The age is "+age);

}

}

1. The program is incomplete. Read the comments in the code and try to complete the program so that it performs as described in the documentation.

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!