224k views
4 votes
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.

1 Answer

2 votes

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);

}

}

User Jo Liss
by
5.1k points