Answer:
See Explaination
Step-by-step explanation:
Java Program:
/* Java Program that calculates payroll of a company */
import java.util.Scanner;
public class Main
{
//Main method
public static void main(String[] args) {
//Scanner class object
Scanner reader = new Scanner(System.in);
//Array to hold names
String[] names = new String[3];
//Array to hold hourly rate
double[] hourlyRate = new double[3];
//Array to hold hours worked
double[] hoursWorked = new double[3];
//Reading data from User
for(int i=0; i<3; i++)
{
System.out.print("\\Enter name of Employee #" + (i+1) + ": ");
names[i] = reader.nextLine();
System.out.print("Enter Hourly rate of Employee #" + (i+1) + ": ");
hourlyRate[i] = reader.nextDouble();
System.out.print("Enter Hours Worked by Employee #" + (i+1) + ": ");
hoursWorked[i] = reader.nextDouble();
reader.nextLine();
}
//Reading tax rate
System.out.print("\\\\Enter tax rate (between 0 and 1.0): ");
double taxRate = reader.nextDouble();
double companyWithholdTax = 0.0;
System.out.printf("\\ %-15s %-15s %-15s %-15s \\", "Employee Name", "Pay Before Tax", "Tax Deducted", "Pay after Tax");
double tax, payBefore, payAfter;
//Printing result
for(int i=0; i<3; i++)
{
//Before tax
payBefore = hoursWorked[i] * hourlyRate[i];
//Computing tax
tax = payBefore * taxRate;
//After taxRate
payAfter = payBefore - tax;
companyWithholdTax += tax;
System.out.printf("\\ %-18s %-15.2f %-15.2f %-15.2f ", names[i], payBefore, tax, payAfter);
}
System.out.printf("\\\\Total amount of taxes company withhold: %.2f \\\\", companyWithholdTax);
}
}