import java.io.*;
import java.util.*;

/*******************************************************
 * The program demonstrates reading from a file by using 
 * Scanner class and working with PrintWriter class for outputs
 * 
 * @author Murat Akhmetov
 * @version V1 - 01/22/07
 * Lab4 / Section 0002
 *******************************************************/ 
public class IO_akhmetma_Remember
{
    private static Scanner        dateScanner;// for inputing
    private static PrintWriter    screen;// for outputing
    


    public static void main(String[] args)
    {
       GregorianCalendar        today;// holds today's date
       String                   name;
		 File                     dates;// holds a file containing
		                                // some information with to dates
       
       today    = new GregorianCalendar();
       screen   = new PrintWriter(System.out);

       // outputs today's date
       screen.printf(Locale.US, "\nToday's Date: %1$te %1$tB %1$tY\n", today);
       screen.flush();       

       // the loop reads from files whose names are entered in command
		 // line by calling processDates() method and the length of args
		 // is equal to the number of files to be read
       for (int i = 0; i < args.length; i++) 
		 {
		    dates = new File(args[i]);// initializes dates by a file's name
			                           // which has index i in args
												
			 // uses try-catch because FileNotFoundException can be thrown
			 // while executing the line: dateScanner = new Scanner(dates);
		    try
		    {
             dateScanner = new Scanner(dates);// initializes dateScanner by using
				                                  // the file currently initialized
															 // to dates
				 
				 processDates(today);// calls the method to process the
				                     // information found in files
		    }
		    catch(FileNotFoundException e)
		    {
			    // outputs the name of a file which caused the exception
		       screen.println("The file \"" + dates + "\" is not found!");
				 screen.flush();
	   	 }
		 }
    }
    

    /*******************************************************
    * The method outputs the information found in files which
    * is related to today's date
    *******************************************************/ 
    private static void processDates(GregorianCalendar today)
    {
       int           day, month;              
       String        name;
       

       // Use the '\t' (tab) and '/' characters as delimiters
       dateScanner.useDelimiter("[\t/]");
          
       // the loop reads from a file and outputs the string which is assigned
		 // to name and which has preceeding date matched with today's date
       while (dateScanner.hasNext())
       {
          month = dateScanner.nextInt();// reads month from a file
          day   = dateScanner.nextInt();// reads day from a file
          name  = dateScanner.nextLine();// reads the string coming after the date

          // if the date read from the file matches today's
			 // date the string name is outputed
          if ((month == (today.get(Calendar.MONTH)+1)) && 
              (day   == today.get(Calendar.DAY_OF_MONTH)))
          {
			    // outputs String name
             screen.printf("%s\n", name);
             screen.flush();
          }
       }
    }
    

}
