Krassi_Daskalova

SoftuniParking

Jul 9th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import java.lang.reflect.Array;
  2. import java.util.LinkedHashMap;
  3. import java.util.Map;
  4. import java.util.Scanner;
  5.  
  6. public class SoftUniParking {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. int n = Integer.parseInt(scanner.nextLine());
  10.  
  11. Map<String, String> registered = new LinkedHashMap<>();
  12.  
  13. for (int i = 1; i <= n; i++) {
  14. String[] input = scanner.nextLine().split(" ");
  15. if (input[0].equals("register")) {
  16. if (!registered.containsKey(input[1])) {
  17. registered.put(input[1], input[2]);
  18. System.out.printf("%s registered %s successfully%n", input[1], input[2]);
  19. } else {
  20. System.out.printf("ERROR: already registered with plate number %s%n", registered.get(input[1]));
  21. }
  22. }
  23. if (input[0].equals("unregister")) {
  24. if (registered.containsKey(input[1])) {
  25. registered.remove(input[1]);
  26. System.out.printf("%s unregistered successfully%n", input[1]);
  27. } else {
  28. System.out.printf("ERROR: user %s not found%n", input[1]);
  29. }
  30. }
  31. }
  32. for (Map.Entry<String, String> entry : registered.entrySet()) {
  33. System.out.printf("%s => %s%n", entry.getKey(), entry.getValue());
  34. }
  35. }
  36. }
Add Comment
Please, Sign In to add comment