Payroll Write a program that reads the following information
(Payroll) Write a program that reads the following information and prints a payroll statement:
Employee\'s name (e.g., Smith).
Number of hours worked in a week (e.g., 10).
Hourly pay rate (e.g., 6.75).
Federal tax withholding rate (e.g., 20%).
State tax withholding rate (e.g., 9%).
Use console input and output. A sample run of the console input and output is shown in Figure below:
Solution
PayrollTest.java
import java.util.Scanner;
public class PayrollTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter Emplyee Name :\");
String name = scan.nextLine();
System.out.println(\"Enter Number of hours worked :\");
int hours = scan.nextInt();
System.out.println(\"Enter Pay rate :\");
double rate = scan.nextDouble();
System.out.println(\"Enter Federal tax withholding rate :\");
double federalTaxRate = scan.nextDouble();
System.out.println(\"Enter State tax withholding rate :\");
double stateTaxRate = scan.nextDouble();
double gross = hours * rate;
double federalTax = (gross * federalTaxRate) /100;
double stateTax = (gross * stateTaxRate)/100;
double netPay = gross - stateTax - federalTax;
System.out.println(\"Employee\'s name: \"+name);
System.out.println(\"Number of hours worked in a week : \"+hours);
System.out.println(\"Hourly pay rate: \"+rate);
System.out.println(\"Federal Tax: \"+federalTax);
System.out.println(\"State Tax: \"+stateTax);
System.out.println(\"Gross Pay: \"+gross);
System.out.println(\"Net Pay: \"+netPay);
}
}
Output:
Enter Emplyee Name :
Smith
Enter Number of hours worked :
10
Enter Pay rate :
6.75
Enter Federal tax withholding rate :
20
Enter State tax withholding rate :
9
Employee\'s name: Smith
Number of hours worked in a week : 10
Hourly pay rate: 6.75
Federal Tax: 13.5
State Tax: 6.075
Gross Pay: 67.5
Net Pay: 47.925

