Advertisement
deyanmalinov

05. SoftUni Parking

Mar 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.LinkedHashMap;
  4. import java.util.Map;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.         int lines = Integer.parseInt(scan.nextLine());
  11.         Map<String, String> userAndcar = new LinkedHashMap<>();
  12.         String comand = "";
  13.         String driver = "";
  14.         String license = "";
  15.  
  16.         for (int i = 0; i < lines; i++) {
  17.             String[] userData = scan.nextLine().split(" ");
  18.  
  19.             if (userData.length ==3){
  20.                 comand = userData[0];
  21.                 driver = userData[1];
  22.                 license = userData[2];
  23.                 if (comand.equals("register")){
  24.                     if (userAndcar.containsKey(driver)){
  25.                         System.out.printf("ERROR: already registered with plate number %s\n", license);
  26.                     }else {
  27.                         userAndcar.put(driver, license);
  28.                    System.out.printf("%s registered %s successfully\n", driver, license);
  29.                     }
  30.                 }
  31.             }
  32.             else if (userData.length == 2) {
  33.                 comand = userData[0];
  34.                 driver = userData[1];
  35.                 if (comand.equals("unregister")) {
  36.                     if (userAndcar.containsKey(driver)){
  37.                         userAndcar.remove(driver);
  38.                     System.out.printf("%s unregistered successfully\n", driver);
  39.                     }else {
  40.                         System.out.printf("ERROR: user %s not found\n", driver);
  41.                     }
  42.  
  43.                 }
  44.  
  45.                 }
  46.         }
  47.         for (Map.Entry<String, String> entry : userAndcar.entrySet()) {
  48.             System.out.printf("%s => %s\n", entry.getKey(), entry.getValue());
  49.         }
  50.  
  51.  
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement