-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStaffManager.java
More file actions
178 lines (160 loc) · 4.59 KB
/
Copy pathStaffManager.java
File metadata and controls
178 lines (160 loc) · 4.59 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
167
168
169
170
171
172
173
174
175
176
177
178
import java.util.ArrayList;
import java.util.Scanner;
/**
* Represents the Staff Manager at the restaurant.
* Manages the Staff in the restaurant.
* @author Tan Zheng Kai
* @version 16.0
* @since 2021-11-13
*/
public class StaffManager {
/**
* List of staffs working in the restaurant.
*/
private ArrayList<Staff> staffList;
/**
* Creates the StaffManager storing the list of staff
* that works at the restaurant.
*/
public StaffManager() {
this.staffList = new ArrayList<Staff>();
Staff staff1 = new Staff("Han Kang", 'M', "MANAGER", 1);
Staff staff2 = new Staff("Ming Jun", 'F', "CASHIER", 2);
Staff staff3 = new Staff("Zheng Kai", 'F', "SERVER", 3);
Staff staff4 = new Staff("Benjamin", 'M', "CHEF", 4);
this.staffList.add(staff1);
this.staffList.add(staff2);
this.staffList.add(staff3);
this.staffList.add(staff4);
}
/**
* Prints the interface for the user to interact with.
*/
public void printInterface(){
Scanner sc = new Scanner(System.in);
int staffID;
int choice;
do {
System.out.println("(1) Add Staff");
System.out.println("(2) Remove Staff");
System.out.println("(3) Print Staff List");
System.out.print("Enter the number of your choice: ");
choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
System.out.println("Adding Staff ..");
System.out.print("Please enter Name: ");
String name = sc.nextLine();
System.out.println("Please enter Staff ID: ");
staffID = sc.nextInt();
sc.nextLine();
System.out.println("Please enter gender");
char gender = sc.nextLine().charAt(0);
boolean validJob = false;
String job = new String();
while (validJob == false){
System.out.println("Please enter job position: ");
job = sc.nextLine();
validJob = checkValidJob(job);
}
addStaff(name, gender, job, staffID);
break;
case 2:
System.out.println("Please enter staff ID of the staff you wish to remove: ");
staffID = sc.nextInt();
sc.nextLine();
deleteStaff(staffID);
break;
case 3:
displayList();
break;
}
} while (choice < 3);
}
/**
* Check if the input job is a valid jobTitle.
* @param job The job that is provided as input.
* @return true if the job is valid.
*/
public boolean checkValidJob(String job){
switch(job){
case "MANAGER": return true;
case "CASHIER": return true;
case "SERVER": return true;
case "CHEF": return true;
}
return false;
}
/**
* Add new Staff to the list of Staffs
* @param name The name of Staff to be added.
* @param gender The gender of Staff to be added.
* @param staffTitle The jobTitle of Staff to be added.
* @param ID The staffID of Staff to be added.
*/
public void addStaff(String name, char gender, String staffTitle, int ID) {
Staff newStaff = new Staff(name, gender, staffTitle, ID);
staffList.add(newStaff);
}
/**
* Delete Staff from the ArrayList of Staff.
* @param ID The staff ID of the Staff to be removed.
*/
public void deleteStaff(int ID) {
Staff staffFound=checkExist(ID);
if(staffFound==null){
System.out.println("No such staff found!");
}
else{
staffList.remove(staffFound);
System.out.println("Staff removed");
}
}
/**
* Prints out the ArrayList of Staff.
*/
public void displayList() {
System.out.println("Staff List:");
int index = 1;
for (Staff staff : staffList){
System.out.println("Staff "+index+":");
System.out.println("---------------------------------------");
staff.printStaffInformation();
index++;
}
}
/**
* Checks if the Staff exists using the ID.
* ID used to check must match the ID of the staff in the list.
* @param ID ID used to check the list of staffs in this staff manager
* @return staff in the staff list.
*/
public Staff checkExist(int ID){
Staff staffFound = null;
boolean idMatch;
for(Staff currentStaff : staffList){
idMatch=currentStaff.checkID(ID);
if(idMatch==true){
staffFound=currentStaff;
break;
}
}
return staffFound;
}
/**
* Gets the staff of this staff manager.
* @param index Index to look for the specific staff.
* @return The Staff of this staff manager.
*/
public Staff getStaff(int index){
return this.staffList.get(index);
}
/**
* Gets the size of the staff list.
* @return the size of the staff list of this staff manager.
*/
public int getSizeOfStaffList(){
return this.staffList.size();
}
}