In: Computer Science
Write a program to help a small company calculate the amount of money to pay its employees. In this simplistic world, the company has exactly three employees. However, the number of hours per employee may vary. The company will apply the same tax rate to every employee
You may separate the processing/calculation step from the output step or you may combine those steps. It is your choice
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("\nEnter 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("\n\nEnter tax rate (between 0 and
1.0): ");
double taxRate = reader.nextDouble();
double companyWithholdTax = 0.0;
System.out.printf("\n %-15s %-15s %-15s %-15s \n",
"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("\n %-18s %-15.2f %-15.2f %-15.2f ",
names[i], payBefore, tax, payAfter);
}
System.out.printf("\n\nTotal amount
of taxes company withhold: %.2f \n\n", companyWithholdTax);
}
}
____________________________________________________________________________________________________
Sample Run: