/*****************************
* Spencer Sayce 
* Section 1 
* 1/22/07
* Lab 4
*
* This class will take in a 
* command-line argument and 
* and use it as a file, then it 
* will find data from the file
* based on the date.
******************************/

import java.io.*;
import java.util.*;

public class IO_saycese_Remember
{
    private static Scanner        dateScanner;
    private static PrintWriter    screen;
    
	/*****************************
	* This method will take in a 
	* command-line argument and 
	* and use it as a file, then it 
	* will find data from the file
	* based on the date.
	******************************/
    public static void main(String[] args)
    {
       GregorianCalendar        today;
       String                   name;       
	   File[]					dates;
       
       dates    = new File[args.length];
       today    = new GregorianCalendar();
       screen   = new PrintWriter(System.out);
	   //creates the array of files
	   for (int i = 0; i < args.length; i++)
	   		dates[i]    = new File(args[i]);
	   		
	   //prints the date
       screen.printf(Locale.US, "\nToday's Date: %1$te %1$tB %1$tY\n", today);
       screen.flush();       
       //runs each command-line file so that the info can be found (based on date)
	   for (int i = 0; i < args.length; i++)
	   {
	   	 try
		 {
		 	dateScanner = new Scanner(dates[i]);
		 }
		 catch(java.io.FileNotFoundException fnf)
		 {
		 }
		 
       	 processDates(today);
       }
    }
    

	/*****************************
	* This method will find data 
	* from a file based on the 
	* date
	* 
	* @param today the date
	******************************/
    private static void processDates(GregorianCalendar today)
    {
       int           day, month;              
       String        name;
       

       // Use the '\t' (tab) and '/' characters as delimiters
       dateScanner.useDelimiter("[\t/]");
          
       //finds the date
       while (dateScanner.hasNext())
       {
          month = dateScanner.nextInt();
          day   = dateScanner.nextInt();
          name  = dateScanner.nextLine();

          if ((month == (today.get(Calendar.MONTH)+1)) && 
              (day   == today.get(Calendar.DAY_OF_MONTH)))
          {
             screen.printf("%s\n", name);
             screen.flush();
          }
       }
    }
    

}
