SHARE
TWEET

SoftUniParking

elvirynwa Mar 18th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.LinkedHashMap;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4.  
  5. public class SoftUniParking {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.  
  11.         Map<String, String> parkingLicenses = new LinkedHashMap<>();
  12.  
  13.         for (int i = 0; i < n; i++) {
  14.             String[] data = scanner.nextLine().split("\\s+");
  15.             String command = data[0];
  16.  
  17.             switch (command) {
  18.                 case "register":
  19.                     String username = data[1];
  20.                     String licensePlateNumber = data[2];
  21.                     if (!parkingLicenses.containsKey(username)) {
  22.                         parkingLicenses.put(username, licensePlateNumber);
  23.                         System.out.println(String.format("%s registered %s successfully", username, licensePlateNumber));
  24.                     } else {
  25.                         System.out.println(String.format("ERROR: already registered with plate number %s", licensePlateNumber));
  26.                     }
  27.  
  28.                     break;
  29.  
  30.                 case "unregister":
  31.                     String unregisterUser = data[1];
  32.                     if (!parkingLicenses.containsKey(unregisterUser)) {
  33.                         System.out.println(String.format("ERROR: user %s not found", unregisterUser));
  34.                     } else {
  35.                         parkingLicenses.remove(unregisterUser);
  36.                         System.out.println(String.format("%s unregistered successfully", unregisterUser));
  37.                     }
  38.                     break;
  39.             }
  40.         }
  41.         for (Map.Entry<String, String> kvp : parkingLicenses.entrySet()) {
  42.             System.out.println(String.format("%s => %s", kvp.getKey(), kvp.getValue()));
  43.         }
  44.     }
  45. }
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