import java.io.*;
// An application that reads data about two people from a file and displays
it..
public class People
{
public static void main (String [] args)
{
DataManager
manager = new DataManager ();
manager.readFile
();
manager.displayData
();
} // main method
} // class People
// A class that reads data about the people and displays it.
class DataManager
{
Person girl, boy;
DataManager ()
{
girl = new Person
();
boy = new Person
();
} // constructor
// Method that reads data about the girl and
the boy from the file, infile.txt.
public void readFile ()
{
try
{
BufferedReader
infile = new BufferedReader (new InputStreamReader (new FileInputStream
("infile.txt")));
girl.readData
(infile);
boy.readData
(infile);
} catch (IOException
e) {System.out.println ("File Error.");}
} // method readFile
// Method that displays the name and age of
the people.
public void displayData ()
{
girl.displayAge
();
boy.displayAge
();
} // method displayData
} // class DataManager
// Class that stores information about a person's name and age.
class Person
{
private String name;
private int age;
// A method to read data from a file.
It uses a buffered reader.
public void readData (BufferedReader infile)
throws IOException
{
name = infile.readLine
();
age = Integer.parseInt
(infile.readLine ());
} // method readData
public void displayAge ()
{
System.out.println
(name + "'s age is " + age);
} // method displayData
} // class Person