I have an assignment to create a payroll program that is read from a file and includes methods. I have first part complete, read the name, hourly wage, hours worked, and dependents. Now I am completely lost how to have it read the above data and produce the following detail data:
- regular hours
- overtime hours
- regular pay
- overtime pay
- gross pay
Here is what I have so far...
import java.io.*;
import java.util.*;
public class Payroll {
public static void main(String [] arg) throws FileNotFoundException {
double hourlyWage=0,hoursWorked=0.0, regularPay = 0, grossPay=0, overtimePay = 0, overtimeHours=0, regularHours=0;
int dependents, count=0;
String fName, lName;
PrintWriter outFile = new PrintWriter(new File("payroll.txt"));
Scanner inFile = new Scanner(new File("weeklyData.txt"));
while(inFile.hasNext()){
fName = inFile.next();
lName = inFile.next();
hourlyWage = inFile.nextDouble();
hoursWorked = inFile.nextDouble();
dependents = inFile.nextInt();
outFile.printf("%1s%10s\n", fName, lName);
outFile.println("***************");
outFile.printf("%5s\n%5s\n%5s\n", "Hourly Wage: $" + hourlyWage, "Hours Worked: " + hoursWorked, "Dependents: " + dependents);
outFile.println("**************");
outFile.printf("%10s%15s%15s%15s%13s\n", "Regular Hours ", "Overtime Hours ", "Regular Pay", "Overtime Pay", " Gross Pay");
outFile.println("\n\n ");
}
grossPay = (hoursWorked * hourlyWage);
outFile.printf("%10s%10s%10s%10s%10s\n", regularHours, overtimeHours, regularPay, overtimePay, grossPay);
outFile.close();
inFile.close();
System.out.println("Reading from file..." + count + " Employees");
}
static double calculateOvertimePay(double hourWorked, double hourlyWage) {
if(((hourWorked -40) * hourlyWage) * 1.5);
}
else {
return 0.0;
}
}
1Randy Marchant 2************** 3Hourly Wage: $28.31 4Hours Worked: 37.25 5Dependents: 4 6********************** 7Regular Hours Overtime Hours Regular Pay Overtime Pay Gross Pay 0.0 0.0 0.0