// Arup Guha
// 4/5/07
// Class for Spring 2007 COP 3330 Assignment #5
// This class manages the basic functionality for HourlyEmployees

import java.text.DecimalFormat;

public class HourlyEmployee extends Employee {

	// Information necessary for all hourly employees.	
	protected double hourlyrate;
	protected int reghoursworked;
	protected double overtimerate;
	protected int overtimeworked;
	
	// Some TAX RATES.
	final protected static double LOW_TAX_RATE = .05;
	final protected static double MID_TAX_RATE = .10;
	final protected static double HIGH_TAX_RATE = .15;
	
	// Basic constructor - each value is set according to the 
	// corresponding formal parameters.
	public HourlyEmployee(String f, String l, int daysv, double rate, 
						  int hrsworked, double orate, int oworked) {
		super(f, l, daysv);
		hourlyrate = rate;
		reghoursworked = hrsworked;
		overtimerate = orate;
		overtimeworked = oworked;
		
	}
	
	// Returns the amount of tax withheld. In particular, the tax withheld
	// is based on the employee's hourly pay rate. If this is less than
	// $6/hr. then 5% of the total income is withheld. Otherwise if it's
	// less than $10/hr 10% of the total income is withheld. If the hourly
	// rate is equal or more than $10/hr, 15% of the income is taxed.
	public double taxwithheld() {
		
		double yearlyincome = totalincome();
		if (hourlyrate < 6)
			return LOW_TAX_RATE*yearlyincome;
		else if (hourlyrate < 10)
			return MID_TAX_RATE*yearlyincome;
		else
			return HIGH_TAX_RATE*yearlyincome;
		
	}
	
	
	// Returns 5% of the employee's REGULAR salary, not including
	// any money made working overtime.
	public double sswithheld() {
		return hourlyrate*reghoursworked*LOW_TAX_RATE;
	}
	
	// Return's the current object's total income, which is the sum of
	// both regular and overtime income.
	protected double totalincome() {
		return hourlyrate*reghoursworked + overtimerate*overtimeworked;
	}
	
	// Mature's the current object one year. In particular, three more
	// vacation days are added (with a cap of 20), $1 is added to the hourly 
	// rate, and $1.50 is added to the overtime rate.
	protected void mature() {
		daysofvacation += 3;
		hourlyrate += 1;
		overtimerate += 1.5;
		if (daysofvacation > 20)
			daysofvacation = 20;
	}
	
	// Prints out the current object's W2 form and matures the object one
	// year.
	public void printw2() {
		DecimalFormat twodec = new DecimalFormat("0.00");
		
		System.out.println("Employee's name: "+first+" "+last);
		System.out.println("Days of Vacation: "+daysofvacation);
		
		System.out.println("Wages,tips,other compensation: "+twodec.format(totalincome()));
		System.out.println("Federal income tax withheld: "+twodec.format(taxwithheld()));
		System.out.println("Social security tax withheld: "+twodec.format(sswithheld()));
		
		mature();
		System.out.println();
	}
}