

import java.io.* ;

class TimeCardTest
{

	BufferedReader stdin = 
		new BufferedReader( new InputStreamReader( System.in ) ) ;
	PrintStream stdout = System.out ;
		
	public static void main(String [] args)
	{
		(new TimeCardTest()).go(args) ;	
	}

	void go(String [] args) 
	{
		TimeCard tc = null;
		
		if ( args.length>0 )
		{
			// deserialize from named file
			try {
				System.out.println("Deserializing object " + args[0] ) ;
				FileInputStream fis = new FileInputStream(args[0]) ;
				ObjectInputStream ois = new ObjectInputStream(fis) ;
				tc = (TimeCard) ois.readObject() ;
				ois.close() ;
			}
			catch (ClassNotFoundException cnfe)
			{
				System.out.println(cnfe) ;
			}
			catch (OptionalDataException ode)
			{
				System.out.println(ode) ;
			}
			catch (IOException ioe)
			{
				System.out.println(ioe) ;
			}
			
			tc.print() ;
		}
		else
		{
			// create a new time card
			tc = new TimeCard() ;
	
			MyDate mdb = new MyDate( 1998, 7, 31 ) ;
			MyDate mde = new MyDate( 1998, 7, 31 ) ;
		
			for ( int i=0; i<3; i++ )
			{
				mdb.setTime( i+1, 30 ) ;
				mde.setTime( i+1, 45 ) ;
				tc.addEntry(mdb, mde, i+1 ) ;
			}
		
			tc.print() ;
			
			try {
				// serialize to file TimeCard.dat
				System.out.println("Serializing object to TimeCard.dat") ;
				FileOutputStream fos = new FileOutputStream("TimeCard.dat") ;
				ObjectOutputStream oos = new ObjectOutputStream(fos) ;
				oos.writeObject(tc) ;
				oos.flush() ;
				oos.close() ;
			}
			catch (IOException ioe)
			{
				System.out.println(ioe) ;
				System.exit(0) ;
			}
		}
		
	}

}
