-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaffManagement.java
More file actions
166 lines (136 loc) · 4.47 KB
/
Copy pathStaffManagement.java
File metadata and controls
166 lines (136 loc) · 4.47 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import java.util.ArrayList;
import java.util.List;
// 1. Base Class
class Staff {
private int code;
private String name;
public Staff(int code, String name) {
this.code = code;
this.name = name;
}
public int getCode() {
return code;
}
public String getName() {
return name;
}
}
// 2. Teacher Class (Inherits from Staff)
class Teacher extends Staff {
private String subject;
private String publication;
public Teacher(int code, String name, String subject, String publication) {
super(code, name);
this.subject = subject;
this.publication = publication;
}
public String getSubject() {
return subject;
}
public String getPublication() {
return publication;
}
}
// 3. Officer Class (Inherits from Staff)
class Officer extends Staff {
private String grade;
public Officer(int code, String name, String grade) {
super(code, name);
this.grade = grade;
}
public String getGrade() {
return grade;
}
}
// 4. Typist Base Class (Inherits from Staff)
class Typist extends Staff {
private int speed;
public Typist(int code, String name, int speed) {
super(code, name);
this.speed = speed;
}
public int getSpeed() {
return speed;
}
}
// 5. Regular Typist Class (Inherits from Typist)
class RegularTypist extends Typist {
private double remuneration;
public RegularTypist(int code, String name, int speed, double remuneration) {
super(code, name, speed);
this.remuneration = remuneration;
}
public double getRemuneration() {
return remuneration;
}
}
// 6. Casual Typist Class (Inherits from Typist)
class CasualTypist extends Typist {
private double dailyWages;
public CasualTypist(int code, String name, int speed, double dailyWages) {
super(code, name, speed);
this.dailyWages = dailyWages;
}
public double getWages() {
return dailyWages;
}
}
// 7. Database Manager Class
class StaffDatabase {
private List<Staff> staffList;
public StaffDatabase() {
staffList = new ArrayList<>();
}
public void addStaff(Staff staff) {
staffList.add(staff);
}
// Retrieve staff by code
public Staff getStaffByCode(int code) {
for (Staff staff : staffList) {
if (staff.getCode() == code) {
return staff;
}
}
return null;
}
// Retrieve teachers by subject
public List<Teacher> getTeachersBySubject(String subject) {
List<Teacher> teachers = new ArrayList<>();
for (Staff staff : staffList) {
// Using instanceof to check if the staff member is a Teacher
if (staff instanceof Teacher && ((Teacher) staff).getSubject().equalsIgnoreCase(subject)) {
teachers.add((Teacher) staff);
}
}
return teachers;
}
}
// 8. Main Driver Class
public class StaffManagement {
public static void main(String[] args) {
StaffDatabase database = new StaffDatabase();
// Adding various staff members to the database
database.addStaff(new Teacher(101, "Alice Smith", "Mathematics", "Pearson Edu"));
database.addStaff(new Teacher(102, "Bob Jones", "Physics", "McGraw Hill"));
database.addStaff(new Officer(201, "Charlie Brown", "Grade A"));
database.addStaff(new RegularTypist(301, "Diana Prince", 85, 45000.0));
database.addStaff(new CasualTypist(302, "Evan Wright", 65, 1500.0));
System.out.println("--- Educational Staff Database Testing ---\n");
// Test 1: Retrieve by Code
System.out.println("Testing getStaffByCode(301):");
Staff retrievedStaff = database.getStaffByCode(301);
if (retrievedStaff != null) {
System.out.println("Found: " + retrievedStaff.getName() + " (Code: " + retrievedStaff.getCode() + ")\n");
}
// Test 2: Retrieve Teachers by Subject
System.out.println("Testing getTeachersBySubject(\"Mathematics\"):");
List<Teacher> mathTeachers = database.getTeachersBySubject("Mathematics");
if (!mathTeachers.isEmpty()) {
for (Teacher teacher : mathTeachers) {
System.out.println("Found Math Teacher: " + teacher.getName() + " (Publication: " + teacher.getPublication() + ")");
}
} else {
System.out.println("No mathematics teachers found.");
}
}
}