Computer Science 122
Assignment 1
Due: January 29, 2002

First create a text file with four lines.  The first should be your name, the second your social security number, then your e-mail address and finally your telephone number.  Save this on your disk.

Next write a Java application to read this information into a class and then display it on the screen.  Your program should have at least two classes.  The first one is the main class that instantiates the second class and calls methods in it.  The data in the second class should correspond with the data in the file.  It should have at least two methods, one to read the data into the class and the other to display the data on the screen.

Hand in a printout of your program together with a disk with the file and the .java and .class files.  You can use the program below to guide you in writing your program.

// Computer Science 122
// <name>
// <data>

import java.io.*;

// An application with a class that reads data about a person from a file and displays it on the screen.
public class People
{
     public static void main (String [] args)
     {
          Person person = new Person ();
          person.readData ();
      person.displayData ();
     } // main method
} // class People

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

     // A method that reads data from a file.  It uses a buffered reader.
     public void readData ()
     {
          try
          {
               BufferedReader infile = new BufferedReader (new InputStreamReader (new FileInputStream ("infile.txt")));
               name = infile.readLine ();
               age = Integer.parseInt (infile.readLine ());
          }
          catch (IOException e) { System.out.println ("I/O error");}
          catch (NumberFormatException e) { System.out.println ("Number format error.");}
     } // method readData

     // A method that displays the data in the class on the screen.
     public void displayData ()
     {
          System.out.println (name + "'s age is " + age);
     } // method displayData
} // class Person