/***********************************************
 * 
 * 
 * @author Kristopher Kalish
 * @version 1 - January 22th, 2007
 * 
 * Lab 4
 * Section 1 
 * 
 ************************************************/
 /*
  *  References and Acknowledgements: I have recieved
  *  no unauthorized help on this assignment.
  *
  */

import java.io.*;
import java.util.*;


public class IO_kalishkl_Remember
{
    // The scanner is for reading in input
    private static Scanner        dateScanner;
    private static PrintWriter    screen;
    

	/**
	 * main() will generate the five potential exceptions
	 * and prompt the user.
	 */
    public static void main(String[] args)
    {
	    // today is used to grab todays date
       GregorianCalendar        today;
       String                   name;
		 File                     dates[];
		 int                      numFiles;  // the number of files passed in
		 
       
       today    = new GregorianCalendar();
       screen   = new PrintWriter(System.out);
		 
		 
		 numFiles = args.length;
		 
		 // make enough file objects to hold all of the args passed in
		 dates = new File[numFiles];
		 
		 // instantiate all of the File objects with the names passed in
		 for(int i = 0; i < numFiles; i++)
		 	dates[i] = new File(args[i]);

       // Print the header
       screen.printf(Locale.US, "\nToday's Date: %1$te %1$tB %1$tY\n", today);
       screen.flush();       
   
	
	    // This big loop will run processDates for each filename passed as an arg
	    for(int i = 0; i < numFiles; i++)
		 {
		    // prepare dateScanner to read in dates from the file passed in
			 // the first argument
			 try
			 {
	           dateScanner = new Scanner(dates[i]);
	       }
			 catch (FileNotFoundException fnfe)
			 {
			     screen.println("Could not find the file '" + args[i] + "'.");
				  screen.flush();
			 }
	
	       // now read in the dates
	       processDates(today);
		    
			 dateScanner.close();
		 }	 

    }
    
    /**
	  * processDates()reads in date data, then prints out the
	  * ones occuring today.
	  */
    private static void processDates(GregorianCalendar today)
    {
	    // integer representations of the dates
       int           day, month;            
		 // the name of the dates  
       String        name;
       

       // Use the '\t' (tab) and '/' characters as delimiters
       dateScanner.useDelimiter("[\t/]");
          
       // keep looping through the input until no more
		 // delimited dates are found
       while (dateScanner.hasNext())
       {
          month = dateScanner.nextInt();
          day   = dateScanner.nextInt();
          name  = dateScanner.nextLine();

          // is the read in date the same as  today?
          if ((month == (today.get(Calendar.MONTH)+1)) && 
              (day   == today.get(Calendar.DAY_OF_MONTH)))
          {
			    // print it out
             screen.printf("%s\n", name);
             screen.flush();
          }
       }
    }
    

}
