In: Computer Science
You are asked to write a program to help a small company calculate the amount of money to pay their 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.
Problem Description
Inputs (entered by user of the program)
• Name of first employee
• Hourly rate
• Number of hours worked
• Name of second employee
• Hourly rate
• Number of hours worked
• Name of third employee
• Hourly rate
• Number of hours worked
• Tax rate (between 0 and 1.0)
Processing and Output
• Calculate and display the amount each employee will be paid before taxes
• Calculate and display the amount each employee will be taxed
• Calculate and display the amount each employee will be paid after taxes have been withheld
• Calculate and display the total amount of taxes the company will withhold
• Display your name
You may separate the processing/calculation step from the output step or you may combine those steps. It is your choice.
CODE IN JAVA:
EmployeeTax.java file:
import java.util.Scanner;
public class EmployeeTax {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
System.out.print("Enter the number
of employees:");
int n = sc.nextInt();
sc.nextLine();
String[] employeeName = new
String[n];
double[] hourlyRate = new
double[n];
int[] hoursWorked = new
int[n];
double taxRate;
for (int i = 0; i < n; i++)
{
int temp = i +
1;
System.out.print("Enter name of employee " + temp + " :");
employeeName[i]
= sc.nextLine();
System.out.print("Enter hourly rate of employee " + temp + "
:");
hourlyRate[i] =
sc.nextDouble();
System.out.print("Enter number of hours worked of employee " + temp
+ " :");
hoursWorked[i] =
sc.nextInt();
sc.nextLine();
}
System.out.print("Enter tax rate :
");
taxRate = sc.nextDouble();
double companyTaxAmount =
0.0;
double amountBeforeTax,
amountAfterTax, taxAmount;
for (int i = 0; i < n; i++)
{
int temp = i +
1;
amountBeforeTax
= hoursWorked[i] * hourlyRate[i];
taxAmount =
amountBeforeTax * taxRate;
amountAfterTax =
amountBeforeTax - taxAmount;
System.out.println("Amount before tax for employee " + temp + " : "
+ amountBeforeTax);
System.out.println("tax amount employee " + temp + " : " +
taxAmount);
System.out.println("Amount after tax for employee " + temp + " : "
+ amountAfterTax);
companyTaxAmount
+= taxAmount;
}
System.out.println("The total
amount of tax the company with held : " + companyTaxAmount);
}
}
OUTPUT: