//Salaries.java
//This program will compute the gross wages for each employee. It will also
//determine the highest and lowest for the week's salary, the total weekly payroll,
//the average salary for the week, and the total amount the company has to pay
//in social security taxes. In addition, the program will count the employees
//that earn more than $500.00 by the end of the week.
import java.util.*;
import java.io.*;
public class Salaries
{
public static void main(String [] args) throws IOException
{
Scanner
fin = new Scanner(new FileReader("Salaries.data"));
Scanner
fin2 = new Scanner(new FileReader("Transaction.data"));
PrintWriter
fout=new PrintWriter(new FileWriter("Salaries.report"));
double [] array = new double [50];
int
numE = 0,
index = 0,
value,
overTimer=0,
variable,
result = 0;
double
hoursWorked,
payRate,
tax,
wages,
overTime,
overHours,
totalTax,
total = 0,
average = 0,
Wages;
fout.println("\n The list of employees gross wages follows: ");
while(fin.hasNextDouble());
{
hoursWorked = fin.nextDouble();
payRate = fin.nextDouble();
if(hoursWorked>40.00)
{
overHours = (hoursWorked-40.00);
overTime=payRate+(payRate*.5);
wages=(overHours*overTime)+(40.00*payRate);
array[numE]=wages;
numE++;
}
else
{
wages=hoursWorked*payRate;
array[numE]=wages;
numE++;
}
fout.printf("%2s%1.2f ","",wages);
}
total = totalWages(array, numE);
fout.printf("Total Wages: %1s%1.2f \n","",total);
fout.printf("Average Wage: %1s%1.2f \n","",average);
index=findLargestSalary(array,numE);
fout.printf("\nThe largest salary is: $%1s%1.2f","",array[index],
" and is at position ", index);
fout.println();
index = findSmallestSalary(array,numE);
fout.printf("The smallest salary is: $%1s%1.2f","",array[index],
" and is at position ",index);
fout.println("\n");
tax=total*.062;
totalTax=tax*2;
fout.printf("Employee withholdings for social security taxes is:%15s$%2s%.2f\n",
"",tax);
fout.printf("The company matching amount for social security taxes is:%9s$%2s%.2f\n",
"",tax);
overTimer=printOverTimer(array,numE);
fout.print("The number of employees that made over $500 this week is: "+overTimer);
while(fin2.hasNextDouble())
{
variable = fin2.nextInt();
switch(variable)
{
case 1:
hoursWorked=fin2.nextDouble();
payRate=fin2.nextDouble();
if(hoursWorked>40.00)
{
overHours=(hoursWorked-40.00);
overTime=payRate+(payRate/2);
wages=(overHours*overTime)+(40.00*payRate);
array[numE]=wages;
numE++;
}
else
{
wages=hoursWorked*payRate;
array[numE]=wages;
numE++;
}
fout.printf("$%1.2f was added to the array.\n" , wages);
break;
case 2:
Wages=fin2.nextDouble();
numE=remove(array, numE, Wages);
fout.printf("\n $ %1.2f was removed from the array. \n", Wages);
break;
case 3:
Wages = fin2.nextDouble();
result = search(array, numE, Wages);
if(result<0)
fout.println("\n $ " +Wages + " was found at index " +result);
else
fout.println("\n $ " + Wages + " was not found in the array.\n");
}
for(int i=0; i<numE; i++)
fout.printf("%1.2f ",array[i]);
}//Closes while
fin.close();//Closes first input file
fin2.close();//closes Transaction
fout.close(); //Closes output file
}//Closes main
///////////////// totalWages /////////////////
//This method will take in the array and calculate the total wages in the company.
public static double totalWages(double [] array, int numE)
{
double
total = 0;
for(int i=0; i<numE; i++)
{
total += array[i];
}
return total;
}//end totalWages
///////////////// computeAverageWage /////////////////
//This method will compute the average wage of employees at the company.
public static double computeAverageWage(double [] array, int numE)
{
double
average,
sum = 0;
average = (double)sum/numE;
return average;
}//end computeAverageWage
///////////////// findLargestSalary /////////////////
//This method will find the highest salary of employees.
public static int findLargestSalary(double [] array, int numE)
{
int
position = 0;
for(int i=0; i<numE; i++)
{
if(array[i]>array[position])
position = i;
}
return position;
}//end findLargestSalary
///////////////// findSmallestSalary /////////////////
//This salary will find the lowest salary of employees.
public static int findSmallestSalary(double [] array, int numE)
{
int
position = 0;
for(int i=0; i<numE; i++)
if(array[i]<array[position])
position = i;
return position;
}//end findSmallestSalary
///////////////// printOverTimer /////////////////
//This method will print if the employee has worked over 500 hours or not.
public static int printOverTimer(double [] array, int numE)
{
int
overTimer = 0;
for(int i=0;i<numE;i++)
{
if(array[i]>500)
overTimer++;
}
return overTimer;
}//end printOverTimer
///////////////// remove /////////////////
//This method removes an inputted number.
public static int remove(double [] array, int numE, double Wages)
{
int
index = 0;
while(index<numE && array[index] != Wages)
index++;
if(index < numE)
{
for(int i=index; i<numE-1; i++)
array[i] = array[i+1];
--numE;
}
return numE;
}//end remove
///////////////// search /////////////////
//This method will search for a user-inputted number.
public static int search(double [] array, int numE, double Wages)
{
int
result=0;
for(int i=0; i<numE && result ==1; i++)
if(array[i]==Wages)
result=1;
return result;
}//end search
}//end program