// Andrew Hoffmann
// Payroll Program Final

import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;

public class ASHfinalmain
{
		static Scanner keyboard = new Scanner(System.in);
		static DecimalFormat formatter = new DecimalFormat("#####0.00");
		static ASHfinalemp emp[] = new ASHfinalemp[20];
		static int i,j,t,o;
	public static void main(String args[])throws Exception
	{

		getData();

		for(int a=0;a<j;a++)
		{
			if (a%2==1)
			{
				emp[a].setFica(true);
			}
			else
				emp[a].setFica(false);
		}

		for(int a=0;a<j;a++)
		{
			if (emp[a].getFicaChoice() == true)
			{
				double emptemp;
				emptemp = emp[a].getRate();
				emp[a].setRate(emptemp * 0.0765);
			}
		}
        getHours();
        showReports();
		showStats();
		raise();
	}


	public static void getData()throws Exception
	{
		FileReader freader;
		BufferedReader inputFile;

		 freader = new FileReader("employee.txt");




	    inputFile = new BufferedReader(freader);

		int idtemp,deptemp,codetemp;
		double ratetemp;
		String lname,fname,mname,str;
		boolean martemp;
		i = 0;
		j = 0;
		str = inputFile.readLine();
		idtemp = Integer.parseInt(str);
				while (idtemp > 0)
				{

					str = inputFile.readLine();
					codetemp = Integer.parseInt(str);
				 	str=inputFile.readLine();
				 	martemp =Boolean.valueOf(str);



				 	str = inputFile.readLine();
				 	deptemp = Integer.parseInt(str);
				 	str = inputFile.readLine();
				 	ratetemp = Double.parseDouble(str);
				 	str = inputFile.readLine();
				 	lname = str;
				 	str = inputFile.readLine();
				 	fname = str;
				 	str = inputFile.readLine();
				 	mname = str;
				 	emp[i] = new ASHfinalemp(idtemp,codetemp,martemp,deptemp,ratetemp,lname,fname,mname);
				 	i++;
				 	j++;
				 	str = inputFile.readLine();
				 	idtemp = Integer.parseInt(str);

				}
	}

	public static void getHours()throws Exception
	{
			boolean status = false;
                        String str;
			int temp1,temp3;
			double hourstemp2;


			do
                        {
                            System.out.println("Please enter the employees id number:");

                            temp3 = keyboard.nextInt();
                            if (temp3 > 0)
                            {

                                temp1 = find(temp3);

                                    if (temp1 < j)
                                    {
                                    System.out.println("Enter the employees hours worked:");
                                    hourstemp2=keyboard.nextDouble();
                                    emp[temp1].setHours(hourstemp2);
                                    }
                                    else
                                        System.out.println("That employee does not exhist");


                            }
                        }while (temp3 != 0);
        }


	public static int find(int temp1)throws Exception
	{
            int n,m;

            for (m= 0; m<j; m++)

                                {
                                            n = emp[m].getId();
                                            if (temp1 == n)
                                            {

                                                temp1 = m;
                                            }



                                 }

                return temp1;
	}

        public static void showReports()
        {
            t = 0;
            for (int a=0;a<j;a++)
            {
                double temp3=emp[a].getGross();
                if (emp[a].getHours() > 0)

                if (temp3 > 0)
                {
                    double total = emp[a].getGross() - emp[a].getTaxes();
                    System.out.println("Pay to the order of " + emp[a].getName() + ", the amount of $" + formatter.format(total) + ".");
                    t++;
                }
            }
        }

        public static void showStats()
        {
            double tempstat = 0;
            double temphours = 0;
            double tempavg = 0;
            double temptemp = 0;

            o = 0;
            for (int a=0;a<j;a++)
            {
                tempstat = emp[a].getGross() + tempstat;
            }
            System.out.println("The total payroll for all employees is $" + formatter.format(tempstat));
            System.out.println("The total number of employees paid this week is " + t);

            for (int g=0;g<j;g++)
            {
                if (emp[g].getHours() > 0)
                temphours = emp[g].getHours() + temphours;
            }
            System.out.println("The total number of hours worked by all employees this week is " + temphours);
            tempavg = temphours / t;
            System.out.println("The average number of hours worked by each employee is " + formatter.format(tempavg));
            double tempavg2;
            tempavg2 = tempstat/temphours;
            System.out.println("The average pay per hour for each employee is $" + formatter.format(tempavg2));
           	double tempgrossavg =0;
           	boolean tempmar;
			for (int a=0;a<j;a++)
			{
				tempmar = emp[a].getMar();
				if (tempmar = true)
				{

					if (emp[a].getGross() > 0)
					{
						temptemp = emp[a].getGross();

						o++;

					}
					tempgrossavg = (temptemp + tempgrossavg)/ o;

				}
				else
					tempgrossavg = 0.00;
			}

            System.out.println("The average gross pay amount for married employees is $" + formatter.format(tempgrossavg));
            double fmount= 0;
            int x = 0;
            for (int a=0;a<j;a++)
            {
				if (emp[a].getFicaChoice() == true)
				{
					fmount += emp[a].getFica();
					x++;
				}
			}
            System.out.println("The total of the FICA Tax is $" + formatter.format(fmount));
            System.out.println("The average FICA Tax amount for the employees is $" + formatter.format(fmount / x));
            System.out.println("The total number of employees contributing in FICA is " + x);
        }

        public static void raise()
        {
			double raisetemp,raiseadd;
			for (int a=0;a<j;a++)
			{
				raisetemp = emp[a].getRate();

				raiseadd = raisetemp * .10;

				raisetemp = raisetemp + raiseadd;

				emp[a].setRate(raisetemp);
				System.out.println("The employees new pay rate is $" + formatter.format(raisetemp) + " per hour.");
			}
		}


}


