import java.io.*;
import java.util.*;
/**===============================================
*   This class takes in two input files and scans
*   each one for dates and the information contained
*   beside those dates. It then prints out all the
*   information that matches the current day's date.
*
*   @author Jonathan Spiker
*   @version 1
*
*   Date: 01-22-07
*   Lab: 4
*   Section: 3
==================================================*/

public class IO_spikerjl_Remember
{
    //used for file input and output
    private static Scanner dateScanner1;
	 private static Scanner dateScanner2;
    private static PrintWriter screen;
    
	/**===============================================
   *   Using command line arguments this method takes
	*   the file names in and scans each then calls the
	*   processDates method.
	*
	*   @param args Command line arguments used for
	*   file names.
	==================================================*/

    public static void main(String[] args)
    {
		 try
		 {
	       GregorianCalendar today;
	       String name1;
			 String name2;
			 File dates1;
			 File dates2;
			 
	       today = new GregorianCalendar();
			 name1 = args[0];
 			 dates1 = new File(name1);
	       dateScanner1 = new Scanner(dates1);
			 
			 //instantiates the second set of objects used
			 //for file input
			 if (args.length > 1)
			 {
			    name2 = args[1];
			    dates2 = new File(name2);
				 dateScanner2 = new Scanner(dates2);
			 }
			 
	       screen = new PrintWriter(System.out);
	
	       screen.printf(Locale.US, "\nToday's Date: %1$te %1$tB %1$tY\n", today);
	       screen.flush(); //flushes output buffer
	
	       processDates(today);
			 
	    }
		 catch (FileNotFoundException fnfe)
		 {
          System.out.println("The file requested was not found");
		 }
    } //end of main

	 /**===============================================
    *   This method goes through each file and scans for
	 *   all the information and prints out the information
	 *   linked to the current date.
	 *
	 *   @param today GregorianCalendar object used for
	 *   today's date.
	 ==================================================*/
    private static void processDates(GregorianCalendar today)
    {
       int           day, month;              
       String        name;
       

       // Use the '\t' (tab) and '/' characters as delimiters
       dateScanner1.useDelimiter("[\t/]");
       
		 //While there is another piece of data, assign it to
		 //variables and test those variables against today's date,
		 //then print out the information that matches that date.
       while (dateScanner1.hasNext())
       {
          month = dateScanner1.nextInt();
          day   = dateScanner1.nextInt();
          name  = dateScanner1.nextLine();

          if ((month == (today.get(Calendar.MONTH)+1)) && 
              (day   == today.get(Calendar.DAY_OF_MONTH)))
          {
             screen.printf("%s\n", name);
             screen.flush();
          }
       }
		 
		 //go through same loop as above except only if there is
		 //data in the second file
		 if (dateScanner2.hasNext())
		 {
	       dateScanner2.useDelimiter("[\t/]");
			 
			 while (dateScanner2.hasNext())
	       {
	          month = dateScanner2.nextInt();
	          day   = dateScanner2.nextInt();
	          name  = dateScanner2.nextLine();
	
	          if ((month == (today.get(Calendar.MONTH)+1)) && 
	              (day   == today.get(Calendar.DAY_OF_MONTH)))
	          {
	             screen.printf("%s\n", name);
	             screen.flush();
	          }
	       }
		 }
    } //end of method
    

} //end of class
