-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPayroll.java
More file actions
47 lines (40 loc) · 1.82 KB
/
Payroll.java
File metadata and controls
47 lines (40 loc) · 1.82 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
package payroll;
/*
* This program calculates state and federal tax withholding based on user input
* based on an exercise in Java Programs to Accompany Programming Logic
* and Design, 2nd Edition by Jo Ann Smith. All code is self-generated to meet
* parameters outlined in the exercise.
*/
import javax.swing.JOptionPane;
public class Payroll {
public static void main(String[] args) {
String grossSalaryString, numberDependentString;
double grossSalary, federalTax, stateTax, dependentDeduction, totalWithholding, netSalary;
int numberDependent;
//Input Gross Salary
grossSalaryString = JOptionPane.showInputDialog("Enter Gross Salary:");
//Input number of Dependents
numberDependentString = JOptionPane.showInputDialog("Enter the number of dependents:");
//Convert salary string to double
grossSalary = Double.parseDouble(grossSalaryString);
//Convert dependent string to double
numberDependent = Integer.parseInt(numberDependentString);
//Calculate federal tax
federalTax = grossSalary * 0.32;
//Calculate state tax
stateTax = grossSalary * 0.07;
//Calculate dependent deduction
dependentDeduction = (numberDependent * 0.04) * grossSalary;
//Calculate total withholding
totalWithholding = federalTax + stateTax - dependentDeduction;
//Calculate net salary
netSalary = grossSalary - totalWithholding;
//Print out result
System.out.println("State Tax: $" + stateTax);
System.out.println("Federal Tax: $" + federalTax);
System.out.println("Dependents: $" + dependentDeduction);
System.out.println("Salary: $" + grossSalary);
System.out.println("Take-Home Pay: $" + netSalary);
System.exit(0);
}
}