Advertisement
Vasilena

ТЕМА 17

Apr 4th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. //ТЕМА_17 ДОМАШНА РАБОТА//
  2.  
  3. import java.util.Dictionary;
  4. import java.util.Enumeration;
  5. import java.util.Hashtable;
  6. import java.util.Scanner;
  7.  
  8. public class UASD_2_020421_HW {
  9.     public static void main(String[] args) {
  10.         Scanner sc = new Scanner(System.in);
  11.  
  12.         //MAKING A DICTIONARY, BY USING HASHTABLE//
  13.         Dictionary<String, String> MusicDictionary = new Hashtable<>();
  14.  
  15.         //KEY : VALUE//
  16.         MusicDictionary.put("NIGHTMARE", "AVENGED SEVENFOLD");
  17.         MusicDictionary.put("IMMORTALIZED", "DISTURBED");
  18.         MusicDictionary.put("STRAIGHT OUT OF HELL", "HELLOWEEN");
  19.         MusicDictionary.put("TIDES OF DESPAIR", "NOCTURNAL DEPRESSION");
  20.         MusicDictionary.put("OUTLAWED", "ATTILA");
  21.         MusicDictionary.put("SMITE AND IGNITE", "PENTAKILL");
  22.         MusicDictionary.put("DISGUISE", "MOTIONLESS IN WHITE");
  23.         MusicDictionary.put("ONEX", "THREE DAYS GRACE");
  24.  
  25.         //MAKING DIALOGUE WITH THE USER//
  26.         System.out.println("This is a program that allows you to search for a certain band's album by their name or the opposite");
  27.         System.out.println("Please, choose:\nBAND | ALBUM");
  28.         String user = sc.nextLine();
  29.  
  30.         if(user.toLowerCase().equals("album")) { //BY ALBUM NAME//
  31.             Enumeration<String> itemsKey = MusicDictionary.keys(); //Enumerations of keys//
  32.             Enumeration<String> itemsValue = MusicDictionary.elements(); //Enumerations of values//
  33.  
  34.             System.out.println("You can choose from: NIGHTMARE, IMMORTALIZED, STRAIGHT OUT OF HELL, TIDES OF DESPAIR, OUTLAWED, SMITE AND IGNITE, DISGUISE, ONEX");
  35.             System.out.println("Please, enter the album`s name: ");
  36.             String album_name = sc.nextLine();
  37.  
  38.             while (itemsKey.hasMoreElements()) {
  39.                 String currentKey = itemsKey.nextElement();
  40.                 String currentValue = itemsValue.nextElement();
  41.  
  42.                 if(currentKey.equals(album_name.toUpperCase())){
  43.                     System.out.println("This album is performed by: " + currentValue);
  44.                 }
  45.             }
  46.         }else if(user.toLowerCase().equals("band")){ //BY BAND NAME//
  47.             Enumeration<String> itemsKey = MusicDictionary.keys(); //Enumerations of keys//
  48.             Enumeration<String> itemsValue = MusicDictionary.elements(); //Enumerations of values//
  49.  
  50.             System.out.println("You can choose from: AVENGED SEVENFOLD, DISTURBED, HELLOWEEN, NOCTURNAL DEPRESSION, ATTILA, PENTAKILL, MOTIONLESS IN WHITE, THREE DAYS GRACE");
  51.             System.out.println("Please, enter the band`s name: ");
  52.             String band_name = sc.nextLine();
  53.  
  54.             while (itemsKey.hasMoreElements()) {
  55.                 String currentKey = itemsKey.nextElement();
  56.                 String currentValue = itemsValue.nextElement();
  57.  
  58.                 if(currentValue.equals(band_name.toUpperCase())){
  59.                     System.out.println("This band album is: " + currentKey);
  60.                 }
  61.             }
  62.         }
  63.  
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement