-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPayroll.java
More file actions
50 lines (41 loc) · 1.65 KB
/
Copy pathPayroll.java
File metadata and controls
50 lines (41 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.mycompany.payroll;
/**
*
* @author nivasharma
*/
import java.util.Scanner;
public class Payroll {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.print("Enter Employee's name:");
String name = input.next();
System.out.print("Enter number of hours worked:");
double hoursWorked = input.nextDouble();
System.out.print("Enter hourly pay rate:");
double hourlyRate = input.nextDouble();
System.out.print("Enter federal tax withholding rate:");
double fedTaxWithholdingRate = input.nextDouble();
System.out.print("Enter state tax withholding rate:");
double stateTaxWithholdingRate = input.nextDouble();
//note the usefulness of setting variables here
double grossPay = hourlyRate * hoursWorked;
double fedWithholding = grossPay * fedTaxWithholdingRate;
double stateWithholding = grossPay * stateTaxWithholdingRate;
double totalDeduction = fedWithholding + stateWithholding;
double netPay = grossPay - totalDeduction;
System.out.println("Employee name: " + name);
System.out.println("Hours Worked: " + hoursWorked);
System.out.println("Pay Rate: " + hourlyRate);
System.out.println("Gross pay: " + grossPay);
System.out.println("Deductions: ");
System.out.println("\tFed Withholding (" + fedTaxWithholdingRate*100 +
"): " + fedWithholding);
System.out.println("\tState Withholding (" + stateTaxWithholdingRate*100 +
"): " + stateWithholding);
System.out.println("\tTotal Deduction: " + totalDeduction);
System.out.println("Net Pay: " + netPay);
}
}