import javax.swing.JOptionPane;
import java.util.Calendar; //to determine current year

/**
 * Uses a primitive GUI to ask a user to enter their YOB and then
 * prints their age to the nearest year.
 *
 * @author Zach Tomaszewski
 * @version 15 Apr 2008
 */
public class AgeCalculator {

  public static void main(String[] args) {

    final int CURRENT_YEAR = Calendar.getInstance().get(Calendar.YEAR);

    String input = JOptionPane.showInputDialog("Please enter your year of birth: ");
    try {
      int yob = Integer.parseInt(input);
      int age = CURRENT_YEAR - yob;
      JOptionPane.showMessageDialog(null, "Your age is " + age + ".");
    }catch (NumberFormatException nfe) {
      JOptionPane.showMessageDialog(null, "Error: You did not enter a number.\n" +
                                    "Quitting...");
    }
  }

}