import java.io.*;				//Imports the io functions
import java.util.*;			//Imports the util functions.


public class IO_alarifac_Remember
{
	//Declares a global variable dateScanner so that it may be used in
	//any method
    private static Scanner        dateScanner;
	 
	 //Alows for global use for the PrintWriter object that will take in a vaule
	 //and print it back out.
    private static PrintWriter    screen;
    
	/************************************************************************
	* This is the main method of the class Remember.  It allows for the user
	* to input txt files and display that information
	*
	*
	*************************************************************************/

    public static void main(String[] args)
    {
	 	 //Declares an object called today that will store the current date
       GregorianCalendar        today;
		 
		 //Declares a string that will store the names of people whos
		 //birthday conencides with today's date.
       String                   name;  
		 
		 //Declares a File objects that will hold in a list of dates     
		 File							  dates;
       
		 //This instantiates the dates object that will be able to read files that contain dates 
		 //at the first line of arguments. 
		 dates = new File (args [0]);
		 
		 //Instantiates the today object that will get the current day, month, and year.
       today    = new GregorianCalendar();
		 
		 //Instantiates the screen object that will allow the user to input/output text
       screen   = new PrintWriter(System.out);
		 
		 //Prints out the current day, month, and year.
       screen.printf(Locale.US, "\nToday's Date: %1$te %1$tB %1$tY\n", today);
		 
		 //Clears the buffer so that it will clear the buffer.
       screen.flush();       

		//This will catch error exceptions in FileNotFoundErrors
		try
		{
			//This creates a for loop that will allow for multiple readings of txt files.
			for (int i = 0; i < args.length; i++)
			{
				//This will keep on reading txt files until i exceeds the number of txt files put in the
				//arguments
			 	dates = new File (args [i]);
				
				//This instantiates that dateScanner object allowing it to read in the number of 
				//files found in the buffer
      	 	dateScanner = new Scanner(dates);
			
				//Calls the processDates method that will pass in its parameter the object today
      		processDates(today);
			}
		}
		
		//Prints out a statement saying that it could not find the file if there a spelling error or no
		//file existed.
		catch (FileNotFoundException fnfe)
		{
			System.out.println ("There was an error in finding the file.");
		}
    }
    
	/*************************************************************************
	* This method is used to  find the current day, month, and year.  It also
	* finds famous people whos birthday is on the same day as the current
	* date.
	*
	*@param today Finds the current day, month and year
	*
	**************************************************************************/

    private static void processDates(GregorianCalendar today)
    {
       int           day, month;              
       String        name;
       

       // Use the '\t' (tab) and '/' characters as delimiters
       dateScanner.useDelimiter("[\t/]");
          
       //States that while the object dateScanner is ture, it will continute to find the month,
		 //day, and name.  
       while (dateScanner.hasNext())
       {
		 	 //Gets the number of the current month
          month = dateScanner.nextInt();
			 
			 //Gets the number of the current day
          day   = dateScanner.nextInt();
			 
			 //Gets the String of people who birthday is on the current date
          name  = dateScanner.nextLine();
			
			 //Creates and if statment declaring that when retriving the current month and current
			 //day are equal to the month and day specified in the txt files, print out the persons
			 //name.
          if ((month == (today.get(Calendar.MONTH)+1)) && 
              (day   == today.get(Calendar.DAY_OF_MONTH)))
          {
			 	 //Uses the printf to display in the output that person's name
             screen.printf("%s\n", name);
				 
				 //Clears out the new line
             screen.flush();
          }
       }
    }
    

}