Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package HashMap;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Homework {
- public static void fillHashMap(HashMap<String, String> map) {
- map.put("Queen", "A Night at the Opera");
- map.put("Nirvana", "Nevermind");
- map.put("The Beatles", "Let it Be");
- map.put("The Cranberries", "Everybody Else Is Doing It, So Why Can't We?");
- map.put("Blink 182", "Neighborhoods");
- map.put("Radiohead", "In Rainbows");
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- HashMap<String, String> map = new HashMap<>();
- fillHashMap(map);
- System.out.print("\nSearch by album or band: ");
- String dialog = scan.nextLine();
- // СЛУЧАЙ, В КОЙТО ТЪРСИМ ПО ИМЕТО НА ГРУПАТА
- if (dialog.equalsIgnoreCase("band")) {
- System.out.print("Name of the band: ");
- String name = scan.nextLine();
- System.out.println("\nBand: " + name);
- System.out.println("Album: " + map.get(name));
- }
- // СЛУЧАЙ, В КОЙТО ТЪРСИМ ПО ИМЕТО НА АЛБУМА
- if (dialog.equalsIgnoreCase("album")) {
- System.out.print("Name of the album: ");
- String name = scan.nextLine();
- String key = "";
- //ТЪРСИМ КЛЮЧА, КОЙТО ОТГОВАРЯ НА ИМЕТО НА АЛБУМА
- for (Map.Entry<String, String> entry : map.entrySet()) {
- if (entry.getValue().equals(name)) {
- key = entry.getKey();
- }
- }
- System.out.println("\nBand: " + key);
- System.out.println("Album: " + name);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment