Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class HashMapHomeWork {
- public static void Singer(HashMap<String, String>MyDictionary){
- Scanner scan = new Scanner(System.in);
- for (int i = 0; i < 2; i++) {
- System.out.println("Enter singer name: ");
- String SingerName = scan.nextLine();
- for (Map.Entry<String, String> items : MyDictionary.entrySet()) {
- if(items.getKey().equals(SingerName)){
- System.out.println("Album: " + items.getValue());
- }
- }
- }
- }
- public static void Album(HashMap<String, String>MyDictionary){
- Scanner scan = new Scanner(System.in);
- for (int i = 0; i < 2; i++) {
- System.out.println("Enter singer album: ");
- String SingerAlbum = scan.nextLine();
- for (Map.Entry<String, String> items : MyDictionary.entrySet()) {
- if(items.getValue().equals(SingerAlbum)){
- System.out.println("Singer: " + items.getKey());
- }
- }
- }
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- HashMap<String, String> MyDictionary = new HashMap<String, String>(16);
- MyDictionary.put("Eminem", "Kamikaze");
- MyDictionary.put("Wiz Khalifa", "Rolling Papers 2");
- MyDictionary.put("Virgo", "Deva");
- MyDictionary.put("Post Malone", "HollyWood Bleeding");
- System.out.println();
- System.out.println("My Dictionary: " + MyDictionary);
- System.out.println();
- for (int i = 0; i < 2; i++) {
- System.out.println("Choose searching by 1: Singer / 2: Album");
- int answer = scan.nextInt();
- if(answer == 1){
- Singer(MyDictionary);
- }else{
- Album(MyDictionary);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment