Advertisement
deyanmalinov

Printer Queue 2

Mar 23rd, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.ArrayDeque;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         ArrayDeque<String> queue = new ArrayDeque<>();
  8.         String comand = scan.nextLine();
  9.  
  10.         while (!"print".equals(comand)){
  11.             if ("cancel".equals(comand)){
  12.                 if (queue.isEmpty()){
  13.                     System.out.println("Printer is on standby");
  14.                 }else {
  15.                     System.out.println("Canceled "+ queue.poll());
  16.                 }
  17.             }else {
  18.                 queue.offer(comand);
  19.             }
  20.             comand = scan.nextLine();
  21.         }
  22.         for (String s : queue) {
  23.             System.out.println(s);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement