-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicketPaperTechnician.java
More file actions
53 lines (41 loc) · 2.06 KB
/
TicketPaperTechnician.java
File metadata and controls
53 lines (41 loc) · 2.06 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
// To use random sleep intervals between printing requests
import java.util.Random;
public class TicketPaperTechnician implements Runnable {
// Creating the instance of the ServiceTicketMachine for the ticket technician to refill the paper
private final ServiceTicketMachine serviceTicketMachine;
private final ThreadGroup technicianThreadGroup;
private final String ticketTechnicianName;
// Constructor to initialize the ticket technician thread group, name and service ticket machine
public TicketPaperTechnician(ThreadGroup technicianThreadGroup,String ticketTechnicianName, ServiceTicketMachine serviceTicketMachine) {
this.technicianThreadGroup = technicianThreadGroup;
this.ticketTechnicianName = ticketTechnicianName;
this.serviceTicketMachine = serviceTicketMachine;
}
// Getters
@SuppressWarnings("unused")
public ThreadGroup getTechnicianThreadGroup() {
return technicianThreadGroup;
}
public String getTicketTechnicianName() {
return ticketTechnicianName;
}
// Ticket technician refills the paper tray when it becomes less than 200 pages
@Override
public void run() {
// Ticket technician is allowed to refill only 3 times
for (int i = 1; i <= 3; i++) {
// Looping and refills the paper 3 times
serviceTicketMachine.refillPaper();
// Random sleep intervals between printing requests
Random randomTime = new Random();
int random = randomTime.nextInt(10);
try {
Thread.sleep(random * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// Printing the number of times paper has refilled
System.out.println("[Ticket Technician] "+ getTicketTechnicianName() + " is in " + Thread.currentThread().getThreadGroup().getName() + " Finished refilling, packs of paper used : " + ((TicketMachine) serviceTicketMachine).getNoOfPaperPacks() +" ]");
}
}