Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DPM;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int lines = Integer.parseInt(scan.nextLine());
- Map<String, String> userAndcar = new LinkedHashMap<>();
- String comand = "";
- String driver = "";
- String license = "";
- for (int i = 0; i < lines; i++) {
- String[] userData = scan.nextLine().split(" ");
- if (userData.length ==3){
- comand = userData[0];
- driver = userData[1];
- license = userData[2];
- if (comand.equals("register")){
- if (userAndcar.containsKey(driver)){
- System.out.printf("ERROR: already registered with plate number %s\n", license);
- }else {
- userAndcar.put(driver, license);
- System.out.printf("%s registered %s successfully\n", driver, license);
- }
- }
- }
- else if (userData.length == 2) {
- comand = userData[0];
- driver = userData[1];
- if (comand.equals("unregister")) {
- if (userAndcar.containsKey(driver)){
- userAndcar.remove(driver);
- System.out.printf("%s unregistered successfully\n", driver);
- }else {
- System.out.printf("ERROR: user %s not found\n", driver);
- }
- }
- }
- }
- for (Map.Entry<String, String> entry : userAndcar.entrySet()) {
- System.out.printf("%s => %s\n", entry.getKey(), entry.getValue());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement