/********************************************************************************************
*	Eddie Corrales						               5/10/07			                    *
*	Java CM16						                   Final Project		                *
*	Prof. Bam						                   ECEmployeeClassFinal	                *
*					               FINAL			                                        *
*											                                                *
*********************************************************************************************/


import java.util.Scanner;
import java.io.*;
import java.text.DecimalFormat;

public class ECEmployeeClassFinal
{

	/******************************** Declare variables needed ********************************/

	/* Strings */
	private String fname;						//First Name
	private String lname;						//Last Name
	private String Begin;						//String Constructor
	/* Integers */

	private int ID;							    //ID Employee's
	private int depend;						    //Dependents
	private int exempt;						    //Exemption code 1-2-3
	/* Boolean */
	private boolean married;					//Boolean if married
	private boolean choosefica;					//True, if employee participates in fica
	/* Doubles */
	private double payrate;						//Pay per hour
	private double hours = 0;					//Hours worked
	private double payDraft;					//Pay before tax
    private double leftovers;						//Used for calculating time and a half for exempt of 1
    private double taxthat;						//Used to calculate tax
    private double finalpay; 					//Pay after tax deduction
    private double ficamount;                   //Dollar amount sent to FICA
 	/* Finals */
 	private final double tax = .10;				//10 percent tax
 	/////////******* Format Currency *******///////
 	DecimalFormat formatter = new DecimalFormat("#0.00");


	/******************************** CONSTRUCTOR ********************************/


	public ECEmployeeClassFinal(String x)
	   {
		Begin = x;
		Scanner s = new Scanner(Begin).useDelimiter(",");
		ID = s.nextInt();
		exempt = s.nextInt();
		depend = s.nextInt();
		lname = s.next();
		fname = s.next();
		married = s.nextBoolean();
		choosefica = s.nextBoolean();
		payrate = s.nextDouble();
		if (lname == "")
		System.exit(0);
	   }



	/******************************** Get and Set methods ********************************/

	// Set //

	public void setHours(double hour){hours = hour;}
	// Get //

	public String getLname(){return lname;}
	public String getFname(){return fname;}
	public int getID(){return ID;}
	public double getHours(){return hours;}
	public double getPay(){return finalpay;}
	public double getTotalRate(){return payrate;}
	public boolean getMarried(){return married;}
	public boolean getFica(){return choosefica;}
	public double getGrosspay(){return payDraft;}
	public double getTax(){return taxthat;}


	/******************************** Calculate pay ********************************/


	public void calcpay()
	{
    ////****EXEMPT****////
    if(exempt == 1)
    	{
        	if (hours > 40)
          	{
             leftovers = hours - 40;
             payDraft = (((hours-leftovers) * payrate)) + ((leftovers * (payrate * 1.5)));

       		 TAX();
       		}
        	else
            {
             payDraft = hours * payrate;
        	 TAX();
            }
        }

    else if (exempt == 2)
    {
      payDraft = hours * payrate;
      TAX();
    }

    else if (exempt == 3)
    {
      	if(hours > 40)
         hours = 40;
      payDraft = hours * payrate;
   	  TAX();
    }

     else
     {
        System.out.println("Error. Please recheck the exempts.");
            System.exit(0);
     }

	}


	/******************************** TAX ********************************/

	public void TAX()
	{
	  if(payDraft == 0)
       taxthat = 0;
	  else
	   {

        taxthat = payDraft - 200;
	      if (married = true)
	       taxthat = taxthat -100;
	    taxthat = (taxthat - (depend * 50));
	    	if (choosefica = true)
	    	payDraft = payDraft * 1.0765;
	    	payDraft = payDraft * 1.153;
	    	ficamount = payDraft;
	    	if (taxthat < 0)
	       taxthat = 0;
	      else
	      	taxthat = taxthat * (tax);

	 }
	 finalpay = payDraft - (taxthat);
	}


	/******************************** Paychecks ********************************/

	public void printPaychecks()
	{
    calcpay();        ////****Calc paycheck, then display checks by name
    if (hours > 0)
      System.out.println("\nPay to the order of " + this.fname + " " + this.lname + " for the amount of $" + formatter.format(this.finalpay) + " for working " + this.hours + " hours.\n    Taxed $" + formatter.format(taxthat) + " from $" + formatter.format(payDraft) + "\n" );
    else              ////**** If employee did not work at all just display that they did not work and paycheck is $0
      System.out.println("Employee " + this.fname + " " + this.lname + " did not work this week.");
	}




	/**************************** Report, display employee ***********************/

public void printEmp()
{
    System.out.println("Employee " + ID + " " + fname + " " + lname + ". Pay-rate $" +  formatter.format(payrate));
}


public double raise()
{
	double raiseme;
	raiseme = (payrate * .10);
	if (raiseme < 1.00)
	raiseme = 1.00;
	payrate = payrate + raiseme;
	return payrate;
}

}

