-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployeeManagementSystem.java
140 lines (115 loc) · 3.43 KB
/
EmployeeManagementSystem.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import java.util.*;
abstract class Employee{
private int employeeId;
private String name;
private double baseSalary;
public Employee(int employeeId, String name, double baseSalary) {
this.employeeId = employeeId;
this.name = name;
this.baseSalary = baseSalary;
}
public int getEmployeeId() {
return employeeId;
}
public String getName() {
return name;
}
public double getBaseSalary() {
return baseSalary;
}
public void setBaseSalary(double baseSalary) {
this.baseSalary = baseSalary;
}
public abstract double calculateSalary();
public void displayDetails() {
System.out.println("Employee ID: " + employeeId);
System.out.println("Name: " + name);
System.out.println("Base Salary: " + baseSalary);
System.out.println("Final Salary: " + calculateSalary());
}
}
interface Department {
void assignDepartment(String departmentName);
String getDepartmentDetails();
}
// Subclass: FullTimeEmployee
class FullTimeEmployee extends Employee implements Department {
private String department;
private double bonus;
public FullTimeEmployee(int employeeId, String name, double baseSalary, double bonus) {
super(employeeId, name, baseSalary);
this.bonus = bonus;
}
@Override
public double calculateSalary() {
return getBaseSalary() + bonus;
}
@Override
public void assignDepartment(String departmentName) {
this.department = departmentName;
}
@Override
public String getDepartmentDetails() {
return "Department: " + department;
}
@Override
public void displayDetails() {
super.displayDetails();
System.out.println(getDepartmentDetails());
}
}
// Subclass: PartTimeEmployee
class PartTimeEmployee extends Employee implements Department {
private String department;
private int hoursWorked;
private double hourlyRate;
public PartTimeEmployee(int employeeId, String name, double hourlyRate, int hoursWorked) {
super(employeeId, name, 0);
this.hourlyRate = hourlyRate;
this.hoursWorked = hoursWorked;
}
@Override
public double calculateSalary() {
return hoursWorked * hourlyRate;
}
@Override
public void assignDepartment(String departmentName) {
this.department = departmentName;
}
@Override
public String getDepartmentDetails() {
return "Department: " + department;
}
@Override
public void displayDetails() {
super.displayDetails();
System.out.println(getDepartmentDetails());
}
}
public class EmployeeManagementSystem {
public static void main(String[] args) {
List<Employee> employees = new ArrayList<>();
FullTimeEmployee emp1 = new FullTimeEmployee(101, "Ajay Kumar", 5000000, 50000);
emp1.assignDepartment("Engineering");
PartTimeEmployee emp2 = new PartTimeEmployee(102, "Amit Singh", 20, 80);
emp2.assignDepartment("Support");
employees.add(emp1);
employees.add(emp2);
for (Employee emp : employees) {
emp.displayDetails();
System.out.println();
}
}
}
//SampleOutput
//Employee ID: 101
//Name: Ajay Kumar
//Base Salary: 5000000.0
//Final Salary: 5050000.0
//Department: Engineering
//
//Employee ID: 102
//Name: Amit Singh
//Base Salary: 0.0
//Final Salary: 1600.0
//Department: Support