Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ExamPreparation;
- import java.util.ArrayDeque;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class Agency {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ArrayDeque<String> ids = new ArrayDeque<>();
- ArrayDeque<String> agents = new ArrayDeque<>();
- Arrays.stream(scanner.nextLine().split("\\s+")).forEach(ids::push);
- Arrays.stream(scanner.nextLine().split("\\s+")).forEach(agents::offer);
- String line = scanner.nextLine();
- while (!line.equalsIgnoreCase("stop")) {
- String[] tokens = line.split("\\s+");
- String command = tokens[0];
- switch (command) {
- case "add-ID":
- String newId = tokens[1];
- ids.push(newId);
- break;
- case "add-agent":
- String newAgent = tokens[1];
- agents.offer(newAgent);
- break;
- case "remove-ID":
- System.out.printf("%s has been removed.%n", ids.pop());
- break;
- case "remove-agent":
- System.out.printf("%s has left the queue.%n", agents.pollLast());
- break;
- case "sort-ID":
- ids = ids.stream().sorted((x, y) -> y.compareTo(x)).collect(Collectors.toCollection(ArrayDeque::new));
- break;
- }
- line = scanner.nextLine();
- }
- while (!ids.isEmpty() && !agents.isEmpty()) {
- String id = ids.pop();
- String agent = agents.poll();
- System.out.printf("%s takes ID number: %s%n", agent, id);
- }
- while (!ids.isEmpty()) {
- System.out.println("No more agents left.");
- System.out.print("ID number: ");
- System.out.printf("%s ", ids.pop());
- System.out.println();
- }
- while (!agents.isEmpty()) {
- System.out.printf("%s does not have an ID.%n", agents.poll());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement