-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcasestudy3.java
More file actions
105 lines (80 loc) · 2.39 KB
/
Copy pathcasestudy3.java
File metadata and controls
105 lines (80 loc) · 2.39 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
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.ArrayList;
class Staff {
int employeeId;
String name;
String role;
double baseSalary;
double finalSalary;
Staff(int employeeId, String name, String role, double baseSalary) {
this.employeeId = employeeId;
this.name = name;
this.role = role;
this.baseSalary = baseSalary;
}
void calculateSalary() {
switch (role) {
case "Manager":
finalSalary = baseSalary + (baseSalary * 0.20);
break;
case "Developer":
finalSalary = baseSalary + (baseSalary * 0.10);
break;
case "Designer":
finalSalary = baseSalary + (baseSalary * 0.05);
break;
case "Intern":
finalSalary = 1000;
break;
default:
finalSalary = baseSalary;
}
}
void applyDeduction(double amount) {
finalSalary = finalSalary - amount;
}
void showDetails() {
System.out.println("ID: " + employeeId);
System.out.println("Name: " + name);
System.out.println("Role: " + role);
System.out.println("Salary: ₹" + finalSalary);
System.out.println("---------------------");
}
}
class SalarySystem {
ArrayList<Staff> staffList = new ArrayList<>();
void addEmployee(Staff s) {
staffList.add(s);
}
Staff findEmployeeById(int id) {
for (Staff s : staffList) {
if (s.employeeId == id) {
return s;
}
}
return null;
}
void calculateAllSalaries() {
for (Staff s : staffList) {
s.calculateSalary();
s.showDetails();
}
}
}
public class casestudy3 {
public static void main(String[] args) {
SalarySystem system = new SalarySystem();
Staff e1 = new Staff(1, "Rahul", "Manager", 50000);
Staff e2 = new Staff(2, "Priya", "Developer", 40000);
Staff e3 = new Staff(3, "Arjun", "Intern", 0);
system.addEmployee(e1);
system.addEmployee(e2);
system.addEmployee(e3);
system.calculateAllSalaries();
Staff found = system.findEmployeeById(2);
if (found != null) {
found.applyDeduction(2000);
System.out.println("After Deduction:");
found.showDetails();
}
}
}