/*
 * 
 * NumIo.java 
 * The program asks the user for the name of the file to be read. 
 * For each line in the file, the program adds up all of the numbers in the line
 * and then outputs the line followed by the total to another file specified
 * by the user. Once it has finished reading the file, the program outputs
 * the sum of all the numbers in the file.
 * 
 */

import java.awt.*;
import hsa.Console;
import java.io.*;

public class DwiteAge
{

  
  public static void main (String[] args)
  {
    
    String fname;
    
    // Input file
    File dataFile;
    FileReader in;
    BufferedReader readFile;
    
    // Output file
    File outFile;
    FileWriter out;
    BufferedWriter writeFile;
    
    String line;         // The line read from file
    int fileTotal = 0;   // Sum of all numbers in file
    int lineTotal = 0;   // Sum of all numbers in a line
    
    // Variables for processing the line of integers
    final int arraySize = 3;
    String[] date = new String [arraySize];
    int[] intDate = new int [arraySize];
    
    fname = "DATA1.txt";
    dataFile = new File(fname);
    
    fname = "OUT1.txt";
    outFile = new File (fname);
    
    try 
    {
      // Open Input file
      in = new FileReader(dataFile);
      readFile = new BufferedReader(in);
      
      // Open output file
      out = new FileWriter(outFile);
      writeFile = new BufferedWriter(out);
      
      while ((line = readFile.readLine()) != null ) 
      {
        date = line.split(" ");
        for (int i = 0; i < arraySize; i++)
        {
          intDate[i] =  Integer.parseInt(date[i]);
        }
        
        if (intDate[2] > 1997)
        {
          writeFile.write("too young");
        }
        else if (intDate[2] < 1997)
        {
          writeFile.write("old enough");
        }
        else
        {
          if (intDate[1] > 10)
          {
            writeFile.write("too young");
          }
          else if (intDate[1] < 10)
          {
            writeFile.write("old enough");
          }
          else
          {
            if (intDate[0] <= 27)
            {
              writeFile.write("old enough");
            }
            else 
            {
              writeFile.write("too young");
            }
          }
        }
        
        // Write the total of this line to the output file
        writeFile.newLine();
      }
      
      // Close the input file
      readFile.close();
      in.close();
      
      // Close the output file
      writeFile.close();
      out.close();
    }
    catch (FileNotFoundException e)
    {
      System.out.println("File does not exist or could not be found.");
      System.out.println("FileNotFoundException: " + e.getMessage());
    } 
    catch (IOException e) 
    {
      System.out.println("Problem reading file.");
      System.out.println("IOException: " + e.getMessage());
    }
  } // main method
} // class

