ITEC 120 Back to Assignment index page
   
Program 3 - A valid birthday
Submit your program file in a folder called RU07 in your directory on neelix.

Write a java program which asks the user to enter their birthdate, and validates each piece of input. The program will print out the date and tell whether or not the year was a leap year.

How to figure out leap years:

If the year is divisible by 4, it's a leap year UNLESS it's divisible by 100, in which case it's not a leap year UNLESS it's divisible by 400, in which case it is a leap year. If the year is not divisible by 4, it's not a leap year.

Put another way, it's a leap year if a) it's divisible by 400, or b) it's divisible by 4 and it's not divisible by 100. So 1600 and 1512 are leap years, but 1700 and 1514 are not.



Sample run:
Program displays:

Enter the year of your birthday:

User enters: 78
Program displays: Enter a 4 digit year:
User enters: 2978
Program displays: 2978 is in the future! Enter a valid year:
User enters: 1978
Program displays:

Enter the month of your birthday (1-12):

User enters: 0
Program displays:

Eyou must enter a month between 1 and 12.

User enters: 22
Program displays:

you must enter a month between 1 and 12.

User enters: 2
Program displays: Enter the day of your birthday (1-28)
User enters: 23
Program displays: Your birthday: February 23, 1978
which was not a leap year.