-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMaintenanceOffice.java
More file actions
72 lines (45 loc) · 1.51 KB
/
MaintenanceOffice.java
File metadata and controls
72 lines (45 loc) · 1.51 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
package org.codedifferently;
import java.util.ArrayList;
import java.util.Iterator;
public class MaintenanceOffice {
private String technician;
public MaintenanceOffice(String technician) {
this.technician = technician;
}
public String updateStat(String problem){
if (problem.equals("NEW")){
return "IN_PROGRESS";
}
else if (problem.equals("IN_PROGRESS")){
return "DONE";
}
return problem;
}
// Work on ONE request by index (one step only)
public void workOneRequest(ArrayList<MaintenanceRequest> requests, int index) {
if (index < 0 || index >= requests.size()) {
System.out.println("Invalid choice.");
return;
}
MaintenanceRequest r = requests.get(index);
String before = r.getStatus();
String after = updateStat(before);
// only allowed statuses
if (!isValidStatus(after)) {
System.out.println("Invalid status change attempted.");
return;
}
r.setStatus(after);
System.out.println("\nUpdated Request:");
System.out.println(r); // shows NEW/IN_PROGRESS/DONE
}
private boolean isValidStatus(String status) {
return status.equals("NEW") || status.equals("IN_PROGRESS") || status.equals("DONE");
}
public String getTechnician() {
return technician;
}
public void setTechnician(String technician) {
this.technician = technician;
}
}