Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

displayPayroll() Overloaded version of the previous method. Takes as input hours

ID: 3907386 • Letter: D

Question

displayPayroll() Overloaded version of the previous method. Takes as input hours, rate of pay, overtime rate, salary, taxes and netIncome and generates to the user the corresponding values. The following is an example of message box produced by this method. NOTE that the method does not return any values to the caller. <-- Overloaded version of the current method in code as displayPayroll

writePayroll() Takes as input hours, salary, taxes, netIncome and the PrintWriter object. The method should then write to the output file the corresponding values. NOTE that the method does not return any values to the caller.

the .txt file location is:

"\Users\w30893\workspace\employees.txt"

output file location is:

"\Users\w30893\workspace\payroll.txt"

public static void userInstruct() {

JOptionPane.showMessageDialog(null, "This program will take a .txt file from AvaCams Inc and allow them an electronic version of their payroll.");

}

public static double findNetIncome(double salary, double taxes) {

return salary - taxes;

}

public static void displayPayroll(int hours, double salary, double taxes, double netIncome) {

JOptionPane.showMessageDialog(null, String.format

("Hourse worked:" + hours, "Salary:" + salary, "Taxes:"

+ taxes, "Net Income:" + netIncome));

}

public static double findTaxes(double salary) {

if(salary <= 250) {

return 0.18 * salary;

} else if(salary <= 550) {

return 0.23 * salary;

} else if(salary <= 1100) {

return 0.28 * salary;

} else {

return 0.33 * salary;

}

}

public static double findSalary(int hoursWorked, int ratePay, double overtimeRate) {

double finalSalary = 0;

double overPay = 0;

if (hoursWorked > 40)

overPay = overtimeRate * (hoursWorked - 40); //calculating the total pay of overtime

if (overPay > 0) //Checking if overpay needs to be added in the final salary

finalSalary = (hoursWorked * ratePay) + overPay;

else

finalSalary = (hoursWorked * ratePay); //else the salary will

finalSalary -= findTaxes(finalSalary);

return finalSalary;

}

public static void main(String[] args) {

}

}

Explanation / Answer

If you have any doubts, please give me comment...

public static void writePayroll(int hours, double salary, double taxes, double netIncome) {

try {

PrintWriter pw = new PrintWriter(new File("\Users\w30893\workspace\payroll.txt"));

pw.println("Hourse worked:" + hours + ", Salary:" + salary + ", Taxes:" + taxes + ", Net Income:" + netIncome);

pw.close();

} catch (IOException e) {

System.out.println("Unable to Write into file");

}

}