-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeptList.java
79 lines (66 loc) · 2.27 KB
/
DeptList.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
import java.io.Serializable;
import java.util.ArrayList;
/** Collection class to hold a list of the departments required for an emergency
* @author Lucian Duta
* @version 20 March 2021
*/
public class DeptList implements Serializable
{
private ArrayList<Dept> deptList;
public final int MAX;
/** Constructor creates the empty department list required for the emergency and sets the maximum number of
* departments that can be called
* @param maxIn: The maximum number of departments in the list
*/
public DeptList(int maxIn)
{
deptList = new ArrayList<>();
MAX = maxIn;
}
/** Checks if the department list is full
* @return Returns true if the list is full and false if it's not
*/
public boolean isFull() { return deptList.size() == MAX; }
/** Checks if the department list is empty
* @return Returns true if it's empty or false if it's not
*/
public boolean isEmpty() { return deptList.size() == 0; }
/** Gets the total number of departments in the list
* @return Returns the total number of departments in the list
*/
public int getTotal() { return deptList.size(); }
/** Adds a new department to the list
*
* @param deptIn: The department to add
* @return Returns true in the department was added successfully and false otherwise
*/
public boolean addDept(Dept deptIn)
{
if(!isFull())
{
deptList.add(deptIn);
return true;
}
else
{
return false;
}
}
/** Searches for a department called for the emergency
* @param typeIn: The type of the department to search for
* @return: Returns the department with the type specified or null if not found
*/
public Dept search (String typeIn)
{
for(Dept currentDept: deptList) //accessing each department in the list
{
if(currentDept.getType().equals(typeIn)) //testing for the specific type of department
{
return currentDept;
}
}
return null;
}
@Override
public String toString() { return "\nDepartments:" + deptList.toString(); }
}