Advertisement
Krassi_Daskalova

Printer Queue

Jan 26th, 2022
826
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayDeque;
  2. import java.util.Scanner;
  3.  
  4. public class PrinterQueue {
  5.     public static void main(String[] args){
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String command = scanner.nextLine();
  9.         ArrayDeque<String> queue = new ArrayDeque<>();
  10.  
  11.         while (!command.equals("print")){
  12.             if(command.equals("cancel")){
  13.                 if(queue.isEmpty()){
  14.                     System.out.println("Printer is on standby");
  15.                 }else{
  16.                     String cancelled = queue.poll();
  17.                     System.out.println("Canceled " + cancelled);
  18.                 }
  19.             } else {
  20.                 queue.offer(command);
  21.             }
  22.             command = scanner.nextLine();
  23.         }
  24.         for (String file : queue) {
  25.             System.out.println(file);
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement