-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinalSalary.java
83 lines (71 loc) · 2.6 KB
/
FinalSalary.java
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
import java.io.*;
import java.util.Scanner;
public class FinalSalary {
public static double basicSalary;
public static void main(String[] args) throws InterruptedException {
Scanner sc = new Scanner(System.in);
double perDayPayment = 0;
int noOfDays = 0;
//check invalid input
while (true) {
System.out.println("Enter Payment Per Day: ");
String input = sc.nextLine();
if (input.isEmpty() || input == null) {
System.out.println("Invalid input. Please enter a valid per day payment: ");
continue;
}
try {
perDayPayment = Double.parseDouble(input);
break;
} catch (NumberFormatException e) {
System.out.println("Invalid input. Please enter a valid per day payment: ");
}
}
while (true) {
System.out.println("Enter No of Days: ");
String input = sc.nextLine();
if (input.isEmpty() || input == null) {
System.out.println("Invalid input. Please enter a valid number of days: ");
continue;
}
try {
noOfDays = Integer.parseInt(input);
break;
} catch (NumberFormatException e) {
System.out.println("Invalid input. Please enter a valid number of days: ");
}
}
sc.close();
// creating three threads
Thread t1 = new Thread(new Task1(), "Mainthread");
Thread t2 = new Thread(new Task2(), "thread2");
Thread t3 = new Thread(new Task3(), "thread3");
t1.start();
t1.join();
t2.start();
t3.start();
t2.join();
t3.join();
basicSalary = perDayPayment * noOfDays;
System.out.println("Basic Salary = " + basicSalary);
double finalSalary = basicSalary + Task2.allowances + Task3.epf;
System.out.println("Final Salary: " + finalSalary);
}
}
class Task2 implements Runnable {
public static double allowances;
public void run() {
allowances = Task1.basicSalary * 0.05;
System.out.println("Allowances = " + allowances);
}
}
class Task3 implements Runnable {
public static double epf;
public void run() {
double totalMonthlyEarnings = Task1.basicSalary + Task2.allowances;
double epfDeduction = totalMonthlyEarnings * 0.08;
double employerContribution = totalMonthlyEarnings * 0.12;
epf = epfDeduction + employerContribution;
System.out.println("EPF = " + epf);
}
}