Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ТЕМА_17 ДОМАШНА РАБОТА//
- import java.util.Dictionary;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Scanner;
- public class UASD_2_020421_HW {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- //MAKING A DICTIONARY, BY USING HASHTABLE//
- Dictionary<String, String> MusicDictionary = new Hashtable<>();
- //KEY : VALUE//
- MusicDictionary.put("NIGHTMARE", "AVENGED SEVENFOLD");
- MusicDictionary.put("IMMORTALIZED", "DISTURBED");
- MusicDictionary.put("STRAIGHT OUT OF HELL", "HELLOWEEN");
- MusicDictionary.put("TIDES OF DESPAIR", "NOCTURNAL DEPRESSION");
- MusicDictionary.put("OUTLAWED", "ATTILA");
- MusicDictionary.put("SMITE AND IGNITE", "PENTAKILL");
- MusicDictionary.put("DISGUISE", "MOTIONLESS IN WHITE");
- MusicDictionary.put("ONEX", "THREE DAYS GRACE");
- //MAKING DIALOGUE WITH THE USER//
- System.out.println("This is a program that allows you to search for a certain band's album by their name or the opposite");
- System.out.println("Please, choose:\nBAND | ALBUM");
- String user = sc.nextLine();
- if(user.toLowerCase().equals("album")) { //BY ALBUM NAME//
- Enumeration<String> itemsKey = MusicDictionary.keys(); //Enumerations of keys//
- Enumeration<String> itemsValue = MusicDictionary.elements(); //Enumerations of values//
- System.out.println("You can choose from: NIGHTMARE, IMMORTALIZED, STRAIGHT OUT OF HELL, TIDES OF DESPAIR, OUTLAWED, SMITE AND IGNITE, DISGUISE, ONEX");
- System.out.println("Please, enter the album`s name: ");
- String album_name = sc.nextLine();
- while (itemsKey.hasMoreElements()) {
- String currentKey = itemsKey.nextElement();
- String currentValue = itemsValue.nextElement();
- if(currentKey.equals(album_name.toUpperCase())){
- System.out.println("This album is performed by: " + currentValue);
- }
- }
- }else if(user.toLowerCase().equals("band")){ //BY BAND NAME//
- Enumeration<String> itemsKey = MusicDictionary.keys(); //Enumerations of keys//
- Enumeration<String> itemsValue = MusicDictionary.elements(); //Enumerations of values//
- System.out.println("You can choose from: AVENGED SEVENFOLD, DISTURBED, HELLOWEEN, NOCTURNAL DEPRESSION, ATTILA, PENTAKILL, MOTIONLESS IN WHITE, THREE DAYS GRACE");
- System.out.println("Please, enter the band`s name: ");
- String band_name = sc.nextLine();
- while (itemsKey.hasMoreElements()) {
- String currentKey = itemsKey.nextElement();
- String currentValue = itemsValue.nextElement();
- if(currentValue.equals(band_name.toUpperCase())){
- System.out.println("This band album is: " + currentKey);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement