// Both file and printwriter are in the io class
import java.io.*;
import java.util.*;

/**********************************************************************
 * @Trevor Spalt
 * @Lab 4
 * @1/22/07
 * @Section 06
 *********************************************************************/

public class IO_spaltts_Remember
{
    private static Scanner        dateScanner;
    private static PrintWriter    screen;
	 // Declare dates to be a file
    private static File 			 dates;
	/******************************************************************
    * Method purpose: This method is used to get practice with
	 * the PrintWriter method. I will correct the code that is given
	 * and explain each correction I made 
    *****************************************************************/

    public static void main(String[] args)
    {
       GregorianCalendar        today;
       String                   name;       
		 int                      counter;
       counter = 0;
		 
       today    = new GregorianCalendar();
       screen   = new PrintWriter(System.out);
		 
		 // Create a while loop that changes that arg value to get different files
		 do
		 {
		 
		 	// Substantiates dates to get the argument that is passed int
		 	// Here you need to have a file name i.e args
		 	dates    = new File(args[counter]);
		 
    	   screen.printf(Locale.US, "\nToday's Date: %1$te %1$tB %1$tY\n", today);
     	   screen.flush();       
		 	 
		 	// Use try/catch block in case of filenotfound exception
			try
		 	{
		 		// Substantiate dateScanner and get input from date
     		  	dateScanner = new Scanner(dates);
		 	}
		 	catch(FileNotFoundException fnfe)
		 	{
		 		System.out.println("File was not found");
		 	}
		 
    	   processDates(today);
			
			// Add one to counter until there is no more files needed
			counter++;
			System.out.println(counter);
		 }
		 while(counter < 2);
    }
    


    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();
          }
       }
    }
}
