import java.io.*;
import java.util.*;

/*******************************************************************
 * This program reads in one or more than one files, and display
 * events that match current date.
 *
 * @author Lu Tian modifies Prof. Adam's code
 * @version 3
 *******************************************************************/
 // Date: January 17, 2007
 // Section 1
 // Lab 4
public class IO_tianlx_Remember
{
    private static Scanner        dateScanner;
    private static PrintWriter    screen;
   
	/**
	 * The main() method display information from the file 
	 * that user inputs.
	 *
	 * @param args		Command line, which takes file in. 
	 **/
    public static void main(String[] args)
    {
   	 // Declarations 
		 File						  dates;
		 GregorianCalendar     today;
       String                name;       

       // Instantiate the variables
		 today    = new GregorianCalendar();
       screen   = new PrintWriter(System.out);
		 
		 //Print the first line, but not read from file yet.
		 screen.printf(Locale.US, "\nToday's Date: %1$te %1$tB %1$tY\n", today);
       screen.flush();
		 
		 //To check if there is a file as an argument.
		 if(args.length > 0)
		 {
		 	for(int i = 0; i < args.length; i++)
		 	{
		 		dates	 = new File(args[i]);
			  
       		try
		 		{    
		 			dateScanner = new Scanner(dates);
					processDates(today);
		 		}
		 		catch(FileNotFoundException fnfe)
		 		{
		 			screen.println("This file cannot be found. " +
								   	"Please make sure this file exist.");
					screen.flush();
					
		 		} //end try-catch block
			} // end for()
		 }//end if
		 else
		 {
		 	screen.println("You didn't enter any argument in.");
			screen.flush();
		 } //end else    
    } //end main()
    


  	/**
	 * This method processes the date that matchs the  
	 * current date.
	 *
	 * @param today	 The current date from GregorianCalendar 
	 **/  
	 private static void processDates(GregorianCalendar today)
    {
       int           day, month;              
       String        name;
       

       // Use the '\t' (tab) and '/' characters as delimiters
       dateScanner.useDelimiter("[\t/]");
          
          
       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();
          } //end if
       } // end while loop
    } // end processDates() method
} // end class
