RGAlex

O5. SoftUni Parking / Maps, Lambda and Stream API - Exercise

Mar 8th, 2021
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. package MapsLambdaStreamAPI.Exercise;
  2.  
  3. import java.util.*;
  4.  
  5. public class O5SoftUniParking {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int x = Integer.parseInt(scanner.nextLine());
  9.         Map<String, String> people = new LinkedHashMap<>();
  10.  
  11.         for (int i = 0; i < x; i++) {
  12.             List<String> type = Arrays.asList(scanner.nextLine().split(" "));
  13.             String name = type.get(1);
  14.             switch (type.get(0)) {
  15.                 case "register":
  16.                     String numberPlate = type.get(2);
  17.                     if (people.containsKey(name)) {
  18.                         System.out.printf("ERROR: already registered with plate number %s%n", numberPlate);
  19.                     }else{
  20.                         people.put(name, numberPlate);
  21.                         System.out.printf("%s registered %s successfully%n", name, numberPlate);
  22.                     }
  23.                     break;
  24.                 case "unregister":
  25.                     if (people.containsKey(name)) {
  26.                         System.out.printf("%s unregistered successfully%n", name);
  27.                         people.remove(name);
  28.                     } else {
  29.                         System.out.printf("ERROR: user %s not found%n", name);
  30.                     }
  31.                     break;
  32.             }
  33.         }
  34.         people.forEach((key, value) -> System.out.println(key + " => " + value));
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment