Practice with Text Files

import java.io.*;

public class Attendance extends IBIO   // download IBIO.java    
   
{  public static void main(String[] args)
   {  new Attendance(); }
   
   String[] names = new String[1000];
   
   public Attendance()
   {
      loadData(names);
      showData(names);
      addData(names);
      sortData(names);
      saveData(names);
   }
   
   public void loadData(String[] names)
   {
      try
      {
         int count = 0;
         BufferedReader data = new BufferedReader(new FileReader("absent.txt"));
         while (data.ready())
         {  
            names[count] = data.readLine();  
            count = count + 1;
         }
         data.close();
      }
      catch (IOException ex)
      {  
         makeEmptyFile();
      }
   }
   
   public void makeEmptyFile()
   {
      names[0] = "zzz";
      saveData(names);
   }
   
   public void showData(String[] names)
   {
      int x = 0;
      while ( !names[x].equals("zzz") )
      {
         output(names[x]);
         x = x + 1;
      }
   }
   
   public void addData(String[] names)
   {
      String newName = input("Absent name: ");
      int x = 0;
      while ( !names[x].equals("zzz") )
      {  x = x + 1;  }
      names[x] = newName;
      names[x+1] = "zzz";
   }
   
   public void sortData(String[] names)
   {
   }

   public void saveData(String[] names)
   {
      try
      {
         PrintWriter data = new PrintWriter(new FileWriter("absent.txt"));
         int x = 0;
         while ( !names[x].equals("zzz") )
         {
            data.println(names[x]);
            x = x+1;
         }
         data.println(names[x]);
         data.close();
      }
      catch (IOException ex)
      {  output("Error = " + ex); }
   }
   
}

/*******************

(1) Copy the program and run it.  You will also need a copy of IBIO.java.

(2) Explain the purpose of makeEmptyFile().

(3) Add a few names to the absent list by running the program
    several times.

(4) From a usability standpoint, explain why the user interface
    is NOT adequate for the task.

(5) Explain the difference between a Sequential Access File
    and a Random Access File.  Which one is used in this program?

(6) Can duplicate names be added in this program?
    
(7) Create a FIND method that searches for a name in the names[] list.

(8) Change the addData method so it calls FIND to check whether
    a name is already in the list.  If the name is already there,
    it should NOT be added again (e.g. no duplicates).
    
(9) Write commands for the SORT method, to sort the names into
    alphabetical order.  It must leave "zzz" at the end - don't move it.
    
(10) Explain why the try..catch.. commands are required.


********************/