Repository navigation
Expand file tree
/
Copy pathDepartment.java
More file actions
executable file
·70 lines (54 loc) · 2.02 KB
/
Copy pathDepartment.java
File metadata and controls
executable file
·70 lines (54 loc) · 2.02 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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package hospitalmanagementsystem;
import java.util.ArrayList;
public class Department {
private int id;
private String name;
private ArrayList<Doctor>doctors;
private int capacity;
// Constructor: Initializes a department with a strict maximum capacity.
// The capacity limit is crucial for managing hospital resources.
public Department(int id, String name, int capacity) {
this.id = id;
this.name = name;
this.capacity = capacity;
this.doctors = new ArrayList<>();
}
// Critical Method: Adds a doctor to the department ONLY if there is space.
// Returns 'true' if successful, or 'false' if the capacity limit has been reached.
// This prevents overbooking staff in a single department.
public boolean addDoctor(Doctor doctor) {
if (doctors.size() >= capacity) {
return false;
}
doctors.add(doctor);
return true;
}
// Getters
public int getId() { return id; }
public String getName() { return name; }
public ArrayList<Doctor> getDoctors() { return doctors; }
public int getCapacity() { return capacity; }
public int getDoctorCount() { return doctors.size(); }
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setDoctors(ArrayList<Doctor> doctors) {
this.doctors = doctors;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
// Returns a summary string showing current occupancy vs. max capacity (e.g., "Doctors: 3/5").
// Useful for displaying department status in the console menu.
@Override
public String toString() {
return "ID: " + id + " | " + name + " | Doctors: " + doctors.size() + "/" + capacity;
}
}