Guest User

parking

a guest
Nov 11th, 2019
255
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.util.LinkedHashMap;
  4. import java.util.Map;
  5. import java.util.Scanner;
  6.  
  7. public class Parking {
  8. public static void main(String[] args) {
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. Map <String, String> usersLicensePlate = new LinkedHashMap<>();
  12.  
  13. int line = Integer.parseInt(scanner.nextLine());
  14. String [] tokens = scanner.nextLine().split("\\s+");
  15.  
  16. for (int i = 0; i < line; i++) {
  17. String register = tokens [0];
  18. String user = tokens [1];
  19.  
  20.  
  21. if (register.equals("register")) {
  22. String licensePlate = tokens [2];
  23. if (usersLicensePlate.containsKey(user)) {
  24. System.out.printf("ERROR: already registered with plate number %s%n", licensePlate);
  25.  
  26. } else {
  27. usersLicensePlate.put(user, licensePlate);
  28. System.out.printf("%s registered %s successfully%n", user, licensePlate);
  29. }
  30. }
  31.  
  32. if (register.equals("unregister")){
  33. if (!usersLicensePlate.containsKey(user)) {
  34. System.out.printf("ERROR: user %s not found%n", user);
  35. } else {
  36. usersLicensePlate.remove(user);
  37. System.out.printf("%s unregistered successfully%n", user);
  38. }
  39. }
  40. tokens = scanner.nextLine().split("\\s+");
  41. }
  42. usersLicensePlate
  43. .forEach((k, v) -> System.out.printf("%s => %s%n", k, v));
  44. }
  45. }
RAW Paste Data