SHARE
TWEET

Untitled

a guest Oct 18th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ExamPreparation;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6. import java.util.stream.Collectors;
  7.  
  8. public class Agency {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         ArrayDeque<String> ids = new ArrayDeque<>();
  12.         ArrayDeque<String> agents = new ArrayDeque<>();
  13.  
  14.         Arrays.stream(scanner.nextLine().split("\\s+")).forEach(ids::push);
  15.         Arrays.stream(scanner.nextLine().split("\\s+")).forEach(agents::offer);
  16.  
  17.         String line = scanner.nextLine();
  18.  
  19.         while (!line.equalsIgnoreCase("stop")) {
  20.             String[] tokens = line.split("\\s+");
  21.             String command = tokens[0];
  22.  
  23.             switch (command) {
  24.                 case "add-ID":
  25.                     String newId = tokens[1];
  26.                     ids.push(newId);
  27.                     break;
  28.                 case "add-agent":
  29.                     String newAgent = tokens[1];
  30.                     agents.offer(newAgent);
  31.                     break;
  32.                 case "remove-ID":
  33.                     System.out.printf("%s has been removed.%n", ids.pop());
  34.                     break;
  35.                 case "remove-agent":
  36.                     System.out.printf("%s has left the queue.%n", agents.pollLast());
  37.                     break;
  38.                 case "sort-ID":
  39.                     ids = ids.stream().sorted((x, y) -> y.compareTo(x)).collect(Collectors.toCollection(ArrayDeque::new));
  40.                     break;
  41.             }
  42.  
  43.             line = scanner.nextLine();
  44.         }
  45.  
  46.  
  47.         while (!ids.isEmpty() && !agents.isEmpty()) {
  48.             String id = ids.pop();
  49.             String agent = agents.poll();
  50.  
  51.             System.out.printf("%s takes ID number: %s%n", agent, id);
  52.         }
  53.  
  54.         while (!ids.isEmpty()) {
  55.             System.out.println("No more agents left.");
  56.             System.out.printf("ID number: %s%n", ids.pop());
  57.         }
  58.  
  59.         while (!agents.isEmpty()) {
  60.             System.out.printf("%s does not have an ID.%n", agents.poll());
  61.         }
  62.  
  63.     }
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top