deyanmalinov

05. Printer Queue

Jul 23rd, 2019
123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayDeque;
  2. import java.util.Deque;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         Deque<String> queue = new ArrayDeque<>();
  9.         String line = "";
  10.         while (!"print".equals(line=scan.nextLine())){
  11.             if (!"cancel".equals(line)){
  12.                 queue.offer(line);
  13.             }else {
  14.                 if (!queue.isEmpty()){
  15.                     System.out.println("Canceled " + queue.poll());
  16.                 }else {
  17.                     System.out.println("Printer is on standby");
  18.                 }
  19.             }
  20.         }
  21.         System.out.println(String.join(System.lineSeparator(), queue));
  22. //         while (queue.size() != 0){
  23. //           System.out.println(queue.poll());
  24.     }
  25. }
RAW Paste Data