-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrinterQueue.java
30 lines (27 loc) · 945 Bytes
/
PrinterQueue.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
package StacksAndQueues_Lab;
import java.util.ArrayDeque;
import java.util.Scanner;
public class PrinterQueue {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayDeque <String> queue = new ArrayDeque<>();
String command = scan.nextLine();
while(!command.equals("print")){
if(!command.equals("cancel")) {
queue.offer(command);
}
if(command.equals("cancel")){
if (queue.isEmpty()) {
System.out.println("Printer is on standby");
} else {
System.out.println("Canceled " + queue.poll());
}
}
command = scan.nextLine();
}
String [] array = queue.toArray(new String[0]);
for (String element: array) {
System.out.println(element);
}
}
}