 //Import the necessary java packages
	import java.io.*;
   import java.util.*;

/**********************************************
* This lab is experimenting with Input and Output from files
* @author - Michael Beaumont  & Elizabeth Adams
* @version - VI - 1/22/07
* Section 1
* Lab 4
************************************************/

    public class IO_beaumomw_Remember
   {
	
//Declare variables that are private to this class
      private static Scanner        dateScanner;
      private static PrintWriter    screen;
    
/**************************************************
*  This is the main method where the variables are declared and instantiated and this is from 
*  where the program actions are run
* @param args this is the command line input
***************************************************/
       public static void main(String[] args)
      {
		
		//Declare variables
         GregorianCalendar  today;
         String   name;      
         File  dates; 
         int length;
			int number;					 
       
		 //Instantiate the variables
         today    = new GregorianCalendar();
         screen   = new PrintWriter(System.out);       
         length    = args.length;  //This tells the number of elements in an array
			number = 0;  //Sets counter equal to zero
       
       
       //This while loop executes until number, which is used bascially as a counter, is one less than the length of the array
		 //This loop is used so that more than one argument can be read from the command line
         while(number < length)
         {
            screen.printf(Locale.US, "\nToday's Date: %1$te %1$tB %1$tY\n", today); //This prints out the date in the correct format
            screen.flush();   //flush the stream 
			  dates 	 = new File(args[number]);  //instantiates the variable dates, but it passes in the command line as arguments

         //This tries to instantiate dateScanner that uses dates as an argument
            try
            {
               dateScanner = new Scanner(dates);
            }
            
			//This catches the File Not Found Exception that is generated by the above try statement
            catch(FileNotFoundException fnfe)
               {
                  System.out.print("The input was an invalid file name");  //This is printed if the file name is not valid
               }
            processDates(today);  //This calls the processDates method
				number++;  //increment the counter
         }
      }
    
/**************************************************
* This is the method where the dates in the file are processed and printed out in the correct form
* @param today is used to call the calendar class that is used to manipulate the calendar fields
***************************************************/
       private static void processDates(GregorianCalendar today)
      {
		
		//Declare variables
         int day;
			int month;              
         String name;
       
      
       // Use the '\t' (tab) and '/' characters as delimiters
         dateScanner.useDelimiter("[\t/]");
          
       //This loop executes until the Scanner has no token in the input.  While executing this loop will constantly
		 //get the month, day and name that is contained in the file
         while (dateScanner.hasNext())
         {
            month = dateScanner.nextInt();  //This is the mont that is in the file
            day   = dateScanner.nextInt();  //This is the day that is in the file
            name  = dateScanner.nextLine(); //This is the name that is in the file
         
           //This boolean expression is used to determine todays date and if it is equal to the day and month that the file contains
			   if ((month == (today.get(Calendar.MONTH)+1)) && 
              (day   == today.get(Calendar.DAY_OF_MONTH)))
            {
               screen.printf("%s\n", name);  //This prints out the name in the file
               screen.flush(); //flush the stream
            }
         }
      }
    
   
   }
