/*
	First class and subclass examples using employees.  This comment has a 
	beginning and end marker.
	Written January 25, 1997, by Kim Bruce.
*/

// This comments begins at "//" and ends at the end of the line.

interface EmployeeSpec{	//  Declares interface implemented by class Employee
	String getName();
	float getWkPay();
}

public class Employee implements EmployeeSpec
/** Class to represent an Employee.  Should be abstract class since getWkPay
	isn't really defined here.	 */
{
// fields

	protected String name;		/** name of employee */
	protected Date birthDate;	/** employee's date of birth */

// constructors  -- note that constructors do not have return type!

	public Employee (String emp_name, Date emp_bday){
	/* post: creates Employee object from name and birthdate	*/
		name = emp_name;			// initialize fields
		birthDate = emp_bday;
	}

// methods

	public String getName()
	// post: Returns name of Employee
	{
		return name;					// return name field
	}
	
	public int getAge()
	/** post: returns the age of the Employee	*/
	{
				// declares today and initializes to today's date
		Date today = new Date();				
				// declare yearDiff and initialize to diff of years
		int yearDiff = (today.getYear() - birthDate.getYear());
		
		if ((today.getMonth() > birthDate.getMonth()) || 
			(today.getMonth() == birthDate.getMonth() && 
						today.getDay() > birthDate.getDay()))
			return yearDiff;					// already had birthday this year
		else
			return yearDiff - 1;			// adjust age if not had birthday yet this year
	}
	
	public float getWkPay()	
	/** post: Return weekly pay.  
		No value assigned for Employees.  Will be overridden in subclasses.	
		Really should be abstract method, but fix later! */
	{
		return 0.0f;				// trailing "f" indicates type is float rather than double.
	}
	
	/** This is the main program.  It is written as a method and usually stuck at 
	end of central class of the program.  It is a procedure since it returns type 
	void.  The parameters are values included on the command line during the actual 
	call of the program.  They must be included, but are not used here.	
	Main is declared to be static because it is only included in the class and not 
	in each object (because it is the main program). */
	public static void main(String args[]){		
			// Create and print my birthday.  Printing implicitly calls toString
		Date kbday = new Date(1948,10,16);							
		System.out.println("My birthday is "+kbday+".");
		
			// Create new employee
		Employee emp = new Employee("Kim Bruce",kbday);
		
			// Print out info on the employee
		System.out.println("Today, the employee, "+emp.getName()+", is "+emp.getAge()
				+" years old.");
		System.out.println("He makes $"+emp.getWkPay()+" per week!");
	}

}