Advertisement
Didart

Printer Queue

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