Computer Science 121
Example that reads data from the keyboard and check the person's age.

import java.io.*;

// 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.displayAge ();
        person.checkAge ();
    } // main method
} // class People

// Class that stores information about a person's name and age.
class Person
{
    private String name;
    private int age;

    // Constructor class that initializes person.
    public Person ()
    {
        name = "";
        age = 0;
    } // constructor

    // A method to reads 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 ("Age: ");
            age = Integer.parseInt (stdin.readLine ());
        }
        catch (IOException e) { System.out.println ("I/O error");}
        catch (NumberFormatException ex) { System.out.println ("Number format error.");}
    } // method readData

    // Method that displays the name and age of a person.
    public void displayAge ()
    {
        System.out.println (name + "'s age is " + age);
    } // method displayAge

    public void checkAge ()
    {
        if (age >= 21)
            System.out.println (name + " is old enough to drink.");
        else
        if (age >= 18)
            System.out.println (name + " is old enough to vote.");
        else
           System.out.println (name + " has a way to go yet.");
 } // method checkAge
} // class Person