35.2k views
1 vote
Write a program that reads in the first name, hourly rate and number of hours worked for 5 people. Print the following details for each employee. Name of employee The number of hours worked Their weekly gross pay.This is calculated by multiplying hours worked times hourly rate. If hours worked per week is greater than 40, then overtime needs to also be included. Overtime pay is calculated as the number of hours worked beyond 40 * rate * 1.5 Taxes withheld Our tax system is simple, the government gets 20% of the gross pay. Net paid The amount of the check issued to the employee.

User Brett
by
4.5k points

1 Answer

1 vote

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

String name;

double hourlyRate;

int hours;

double grossPay = 0.0;

double netPaid = 0.0;

double taxes = 0.0;

Scanner input = new Scanner(System.in);

for (int i=1; i<=5; i++){

System.out.print("Enter the name of the employee #" + i + ": ");

name = input.nextLine();

System.out.print("Enter the hourly rate: ");

hourlyRate = input.nextDouble();

System.out.print("Enter the hours: ");

hours = input.nextInt();

input.nextLine();

if(hours > 40)

grossPay = (40 * hourlyRate) + ((hours - 40) * hourlyRate * 1.5);

else

grossPay = hours * hourlyRate;

taxes = grossPay * 0.2;

netPaid = grossPay - taxes;

System.out.println("\\Name: " + name);

System.out.println("The number of hours worked: " + hours);

System.out.println("The weekly gross pay: " + grossPay);

System.out.println("Taxes: " + taxes);

System.out.println("Net Paid: " + netPaid + "\\");

}

}

}

Step-by-step explanation:

*The code is in Java

Declare the variables

Create a for loop that iterates 5 times (for each employee)

Inside the loop:

Ask the user to enter the name, hourlyRate and hours

Check if hours is above 40. If it is, calculate the gross pay and overtime pay using the given instructions. Otherwise, do not add the overtime pay to the gross pay

Calculate the taxes using given information

Calculate the net paid by subtracting the taxes from grossPay

Print the name, hours, grossPay, taxes, and netPaid

User Hochl
by
4.7k points