/* Dewansh Gautam 2015025 Mayank Kumar 2015055 */ package lab5; import java.util.*; public class DataStructure { public static void TreeSetSong(int k) throws MyException { if(k>(Database.countSong)||k<=0) { //System.out.println("Enter a number between 1-31 as the number of songs in the library are 31"); throw new MyException("(Exception)Enter a number between 1-31 as the number of songs in the library are 31"); } else{ System.out.println(); new Database(); SortedSet tree = new TreeSet<>(); int i; for( i =0; i< Database.countSong ; i++) { String s = Database.song[i].getRating(); s += Database.song[i].getTitle(); tree.add(s); } i=30; String[] array = new String[31]; for(String s : tree) { String temp = s.substring(0,1); array[i] = s; i--; } System.out.printf("Top %d song titles are : ", k); System.out.println(); System.out.println(); System.out.printf("Rating"); System.out.printf(" "); System.out.println("Song Title"); for(int j = 0 ;j(Database.countMovie)||k<=0) { //System.out.println("Enter a number between 1-30 as the number of movies in the library is 30"); try { throw new MyException("(Exception)Enter a number between 1-30 as the number of movies in the library is 30"); } catch (MyException e) { // TODO Auto-generated catch block System.out.println(e.getMessage()); } } else { SortedSet tree = new TreeSet<>(); int i; new Database(); for( i =0; i< Database.countMovie ; i++) { String s = Database.movie[i].getRating(); s += Database.movie[i].getTitle(); tree.add(s); } i=29; String[] array = new String[30]; for(String s : tree) { String temp = s.substring(0,1); if((temp).equals("1")) { array[i] = s; } else if((temp).equals("2")) { array[i] = s; } else if((temp).equals("3")) { array[i] = s; } else if((temp).equals("4")) { array[i] = s; } else { array[i] = s; } i--; } System.out.printf("Top %d movie titles are : ", k); System.out.println(); System.out.println(); System.out.printf("Rating"); System.out.printf(" "); System.out.println("Movie Title"); for(int j = 0 ;j songMap = new HashMap<>(); Map movieMap = new HashMap<>(); for(int i = 0; i> movieSong = new HashMap<>(); String s; if(movie.compareTo("Movie29")<=0) { for(int i = 0 ; i < Database.countMovie ; i++) { s = Database.movie[i].getTitle(); LinkedList songList = new LinkedList<>(); int count = 0; for(int j = 0; j< Database.countSong ; j++) { if((Database.song[j].getmovieName()).equals(s)) { songList.add(Database.song[j].getTitle()); count++; } } if(count == 0) { songList.add(" No song"); } movieSong.put(s, songList); } } else { LinkedList lis = new LinkedList<>(); lis.add("No Song"); movieSong.put(movie, lis); } LinkedList e = movieSong.get(movie); ListIterator iter = e.listIterator(); System.out.printf("The list of songs of %s are :", movie); System.out.println(); while(iter.hasNext()) { System.out.printf(" "); System.out.println(iter.next()); } } public static void HashDirector(String director) { new Database(); Map> movieDirector = new HashMap<>(); String s; for(int i = 0 ; i < Database.countMovie ; i++) { s = Database.movie[i].getDirector(); LinkedList movieList = new LinkedList<>(); int count = 0; for(int j = 0; j< Database.countMovie ; j++) { if((Database.movie[j].getDirector()).equals(s)) { movieList.add(Database.movie[j].getTitle()); count++; } } if(count == 0) { movieList.add("No Director"); try{ throw new MyException("(Exception)"); } catch(MyException e){ System.out.println(e.getMessage()); } } movieDirector.put(s, movieList); } if(!(movieDirector.containsKey(director))) { LinkedList lis = new LinkedList<>(); lis.add("No Movie"); movieDirector.put(director, lis); } LinkedList e = movieDirector.get(director); ListIterator iter = e.listIterator(); System.out.printf("The list of movies of %s are :", director); System.out.println(); while(iter.hasNext()) { System.out.printf(" "); System.out.println(iter.next()); } } public static void FindGenre(String genre) { new Database(); Map> genreMapping = new HashMap<>(); String s; for(int i = 0 ; i < Database.countSong ; i++) { s = Database.song[i].getGenre(); LinkedList songList = new LinkedList<>(); int count = 0; for(int j = 0; j< Database.countSong ; j++) { if((Database.song[j].getGenre()).equals(s)) { songList.add(Database.song[j].getTitle()); count++; } } if(count == 0) { songList.add("No Song"); } genreMapping.put(s, songList); } if(!(genreMapping.containsKey(genre))) { LinkedList lis = new LinkedList<>(); lis.add("No Genre"); genreMapping.put(genre, lis); try{ throw new MyException("(Exception)"); } catch(MyException e){ System.out.println(e.getMessage()); } } LinkedList e = genreMapping.get(genre); ListIterator iter = e.listIterator(); System.out.printf("The list of songs of type %s are :", genre); System.out.println(); while(iter.hasNext()) { System.out.printf(" "); System.out.println(iter.next()); } } }