TsetsoP

hashmap_homework

Apr 5th, 2021 (edited)
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class hashmap_homework {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.  
  8.         HashMap<String, String> MyDictionary = new HashMap<String, String>(16);
  9.  
  10.         MyDictionary.put("Virgo", "Deva");
  11.         MyDictionary.put("Travis Scott", "Utopia");
  12.         MyDictionary.put("Pet Shop Boys", "Hotspot");
  13.         MyDictionary.put("Post Malone", "Beerbongs & Bentleys");
  14.  
  15.         System.out.println();
  16.  
  17.         System.out.println("My Dictionary: " + MyDictionary);
  18.  
  19.         System.out.println();
  20.  
  21.         for (int i = 0; i < 2; i++) {
  22.             System.out.println("Choose searching by 1: Singer / 2: Album");
  23.             int answer = scan.nextInt();
  24.  
  25.             if (answer == 1) {
  26.                 for (int j = 0; j < 2; j++) {
  27.                     System.out.println("Enter singer name: ");
  28.                     String SingerName = scan.nextLine();
  29.                     for (Map.Entry<String, String> items : MyDictionary.entrySet()) {
  30.                         if (items.getKey().equals(SingerName)) {
  31.                             System.out.println("Album: " + items.getValue());
  32.                         }
  33.                     }
  34.                 }
  35.  
  36.             } else {
  37.                 for (int k = 0; k < 2; k++) {
  38.                     System.out.println("Enter singer album: ");
  39.                     String SingerAlbum = scan.nextLine();
  40.                     for (Map.Entry<String, String> items : MyDictionary.entrySet()) {
  41.                         if (items.getValue().equals(SingerAlbum)) {
  42.                             System.out.println("Singer: " + items.getKey());
  43.                         }
  44.                     }
  45.                 }
  46.             }
  47.         }
  48.  
  49.     }
  50. }
  51.  
Add Comment
Please, Sign In to add comment