Advertisement
filipovv

phonebook

Oct 4th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package ObjectsClassesAPIs;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.Scanner;
  6.  
  7. public class Phonebook {
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.         String[] input = scan.nextLine().split("-");
  11.         Map<String, String> phonebook = new HashMap<>();
  12.         while (!input[0].equals("search")) {
  13.  
  14.             if (!phonebook.containsKey(input[0])) {
  15.                 phonebook.put(input[0],input[1]);
  16.             } else {
  17.                 phonebook.replace(input[0], phonebook.get(input[0]),input[1]);
  18.             }
  19.             input = scan.nextLine().split("-");
  20.         }
  21.         String findName = scan.nextLine();
  22.         while (!findName.equals("Stop")) {
  23.             if (phonebook.containsKey(findName)) {
  24.                 System.out.println(findName+" -> "+phonebook.get(findName));
  25.             } else {
  26.                 System.out.println("Contact "+findName+" does not exist.");
  27.             }
  28.             findName = scan.nextLine();
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement