import java.io.*;
import java.util.*;
/***************************************************
 * Remember.java
 * 
 * Krys Stultz
 * 1/10/07
 * Lab 4
 * Section 2
 *
 * @author - Krys Stultz
 * @version - v1.0
 **************************************************/

public class IO_stultzkm_Remember
{
    private static Scanner			dateScanner;
    private static PrintWriter		screen;
    private static File				dates;
    
	/**
	 * main method that runs the program
	 *
	 * @param args	used for inputting file names
	 */
    public static void main(String[] args)
    {
    	GregorianCalendar		today;
		String					name;
		 
		today	= new GregorianCalendar();
		screen	= new PrintWriter(System.out);
				 
		screen.printf(Locale.US, "\nToday's Date: %1$te %1$tB %1$tY\n", today);
		screen.flush();
		
		// Loop until there are no arguments left
		for(int i = 0; i < args.length; i++)
		{
			// set the dates object to the correct argument every iteration
			dates = new File(args[i]);
			
			// attempt to initialize dateScanner to the argument
			try
			{
				dateScanner = new Scanner(dates);
			}
			catch(FileNotFoundException fnfe)
			{
				System.out.println("File not found.\n");
			}       
			
			processDates(today);
		}
		
		screen.printf("\nProgram ended normally.\n");
		screen.flush();
	}
	
	/**
	 * processDates
	 * this method processes the data in the provided files and 
	 * prints the thing for todays date.
	 *
	 * @param today		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/]");
        			
		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();
			}
		}    
	}
}
