CS 120 Lab 10
Nested if Statements and Switch
Tom Linton, http://www.cs.moravian.edu/~linton
Moravian College, Spring 1999


Write a program, called Card.java, which prompts the user (via SimpleGUI methods) for their birthdate. This will require three questions, basically the year in which they were born, the month of their birth and the day of their birth. Upon valid entries for the year, month and day of birth, your program should print a message which determines whether or not the user is of legal age (which you can assume means that they were at least 21 years old on April 1, 1999). Ideally, your program will complain if the user enters an infeasible date of birth, like September 31, 1968 or February 29, 1971. In case you don't know, 30 days has September, April, June and November, all the rest have 31, except February which has 28, unless it is a leap year (the year is divisible by 4) whence February has 29. The three argument method getInt( ) will be useful, and you might set up constants (visibilty of final) such as JANUARY = 1, FEBRUARY = 2, etc. If the user is within one month of legal age (either too young or just old enough) a special message should be printed, indicating the closeness of their age to the limit. The general message you print should include an echoing of the users birthday, in the format:
August 21, 1961
(spell out the month etc.) as well as an indication of whether they are of legal age or not. Some aspects of this assignment are probably best handled with switch blocks. The SimpleGUI class has a useful "menu" command package which makes entering the month easy.

Before starting, you should spend some time thinking about the classes you may need, the data fields, etc. Strive to get all of the code in a single file, and the Card class, should have "just a main method".