-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSalaryOfAnEmployeeUsingMethods.java
More file actions
93 lines (73 loc) · 2.89 KB
/
SalaryOfAnEmployeeUsingMethods.java
File metadata and controls
93 lines (73 loc) · 2.89 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.util.Scanner;
import java.text.DecimalFormat;
public class SalaryOfAnEmployeeUsingMethods {
public static void main(String[] args) {
double numOfWorkedHrs, ratePerHr, monthlyGrossPay, annualGrossPay, incomeTax, annualNetPay;
String cont;
do {
numOfWorkedHrs = getWorkedHrs();
ratePerHr = getRatePerHr();
monthlyGrossPay = computeMonthlyGross(numOfWorkedHrs, ratePerHr);
annualGrossPay = computeAnnualGross(monthlyGrossPay);
incomeTax = computeIncomeTax(annualGrossPay);
annualNetPay = computeAnnualNet(annualGrossPay, incomeTax);
displayResults(monthlyGrossPay, annualGrossPay, incomeTax, annualNetPay);
cont = asksContinue();
} while (cont.equals("Y"));
}
public static double getWorkedHrs() {
Scanner input = new Scanner(System.in);
System.out.print("\nEnter number of hours worked : ");
return input.nextDouble();
}
public static double getRatePerHr() {
Scanner input = new Scanner(System.in);
System.out.print("Enter rate per hour : ");
return input.nextDouble();
}
public static double computeMonthlyGross(double wrkdHrs, double ratePerHr) {
return wrkdHrs * ratePerHr;
}
public static double computeAnnualGross(double monthlyGross) {
return monthlyGross * 12;
}
public static double computeIncomeTax(double annualGross) {
double taxRate, addTax = 0;
if (annualGross <= 250000)
taxRate = 0.0;
else if (annualGross > 250000 && annualGross <= 400000)
taxRate = 0.15;
else if (annualGross > 400000 && annualGross <= 800000) {
addTax = 22500;
taxRate = 0.20;
}
else if (annualGross > 800000 && annualGross <= 2000000) {
addTax = 102500 ;
taxRate = 0.25;
}
else if (annualGross > 2000000 && annualGross <= 8000000) {
addTax = 402500;
taxRate = 0.30;
}
else {
addTax = 2202500;
taxRate = 0.35;
}
return (annualGross * taxRate) + addTax;
}
public static double computeAnnualNet(double annualGross, double incomeTax) {
return annualGross - incomeTax;
}
public static void displayResults(double monthlyGross, double annualGross, double incomeTax, double annualNet) {
DecimalFormat numForm = new DecimalFormat();
System.out.println("Monthly Gross Pay : " + numForm.format(monthlyGross));
System.out.println("Annual Gross Pay : " + numForm.format(annualGross));
System.out.println("Income Tax : " + numForm.format(incomeTax));
System.out.println("Annual Net Pay : " + numForm.format(annualNet));
}
public static String asksContinue() {
Scanner input = new Scanner(System.in);
System.out.println("\nDo you want to continue: (Y or N)");
return input.nextLine();
}
}