// An application with a class that provides information about a person.
class People
{
public static void main (String [] args)
{
Person person
= new Person ();
person.readData
();
person.calculateAge
();
person.displayAge
();
} // main method
} // class People
// Class that stores information about a person's name and age.
class Person
{
private String name;
private int age, birthYear;
// A method to read data from the keyboard.
It uses a buffered reader.
public void readData ()
{
try
{
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
System.out.print ("Name: ");
name = stdin.readLine ();
System.out.print ("Year of Birth: ");
birthYear = Integer.parseInt (stdin.readLine ());
}
catch (IOException
e) { System.out.println ("I/O error");}
catch (NumberFormatException
ex) { System.out.println ("Number format error.");}
} // method readData
// calculateAge determines a person's age, assuming
that he or she was born on January 1.
public void calculateAge ()
{
age = 2004 -
birthYear;
} // calculateAge
// Method that displays the name and age of
a person.
public void displayAge ()
{
System.out.println
(name + "'s age is " + age);
} // method displayAge
} // class Person