package a4;

public class HourlyEmployeeImpl extends EmployeeImpl implements HourlyEmployee {

	private double hourlyRate;
	private double hoursPerWeek;

	HourlyEmployeeImpl(String first_name, String last_name, String job_title,
			int id, double hourly_rate, double hours_per_week) {
		super(first_name, last_name, job_title, id, calculateGrossYearlyIncome(
				hours_per_week, hourly_rate), calculateNet_yearly_Income(
				hours_per_week, hourly_rate), calculateTaxableIncome(
				hours_per_week, hourly_rate), calculateTaxWitheld(
				hours_per_week, hourly_rate));
		this.hourlyRate = hourly_rate;
		this.hoursPerWeek = hours_per_week;

	}

	private static double calculateTaxableIncome(double hours_per_week,
			double hourly_rate) {
		if (calculateGrossYearlyIncome(hours_per_week, hourly_rate) > 25000) {
			return (calculateGrossYearlyIncome(hours_per_week, hourly_rate) - 25000);
		} else {
			return 0;
		}
	}

	private static double calculateGrossYearlyIncome(double hours_per_week,
			double hourly_rate) {
		return 52 * hours_per_week * hourly_rate;
	}

	private static double calculateNet_yearly_Income(double hours_per_week,
			double hourly_rate) {
		return calculateGrossYearlyIncome(hours_per_week, hourly_rate)
				- calculateTaxWitheld(hours_per_week, hourly_rate);
	}

	private static double calculateTaxWitheld(double hours_per_week,
			double hourly_rate) {
		double taxableIncome = calculateTaxableIncome(hours_per_week,
				hourly_rate);
		double taxWithheld = 0;

		if (taxableIncome > 50000) {
			taxWithheld += 5000;
			taxableIncome -= 50000;
			
			if (taxableIncome > 50000) {
				taxWithheld += 7500;
				taxableIncome -= 50000;
				
				if (taxableIncome > 0) {
					taxWithheld += taxableIncome * .25;
				}
				
			} else {
				taxWithheld += taxableIncome * .15;
			}
			
		} else {
			taxWithheld += taxableIncome * .1;
		}

		

		

		return taxWithheld;

	}

	@Override
	public double getHourlyRate() {
		// TODO Auto-generated method stub
		return hourlyRate;
	}

	@Override
	public void setHourlyRate(double rate) {
		// TODO Auto-generated method stub
		this.hourlyRate = rate;
	}

	@Override
	public double getHoursPerWeek() {
		// TODO Auto-generated method stub
		return hoursPerWeek;
	}

	@Override
	public void setHoursPerWeek(double hours_per_week) {
		// TODO Auto-generated method stub
		this.hoursPerWeek = hours_per_week;
	}

}
