diff options
-rw-r--r-- | jMusicHub.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/jMusicHub.java b/jMusicHub.java index 8feab62..2494925 100644 --- a/jMusicHub.java +++ b/jMusicHub.java @@ -1,8 +1,8 @@ import java.util.*; import java.io.*; import java.text.*; + /* TO DO : - * Printing audiobooks sorted by author * Generating the javadoc * Doing the UML Diagramm * Doing the report @@ -386,6 +386,29 @@ public static void listAlbumsByGenre(){ catch (ClassNotFoundException ex) {System.out.println("ClassNotFoundException is caught");} } +public static void listAudioBooksByAuthor(){ + String filename = "audiobooks"; + try { + // Reading the object from a file + FileInputStream file = new FileInputStream(filename); + ObjectInputStream in = new ObjectInputStream(file); + + @SuppressWarnings("unchecked") + ArrayList<AudioBook> audiobooks = (ArrayList<AudioBook>)in.readObject(); + in.close(); + file.close(); + + Collections.sort(audiobooks, Comparator.comparing(AudioBook::getAuthor)); + + System.out.println("\nSaved "+filename+", sorted by name :\n"); + for (AudioBook b : audiobooks ){ + System.out.println(b); + } + } + catch (IOException ex) {System.out.println(filename+ " file missing.");} + catch (ClassNotFoundException ex) {System.out.println("ClassNotFoundException is caught");} + } + /**<h2>extract</h2> * Extract is used to print the content of the files and put them in the ArrayList used to add elements. * @param String filename @@ -578,7 +601,7 @@ public static void listAlbumsByGenre(){ switch(userInput) { case "h" : //page help - System.out.printf("c: add a new song\na: add a new album\n+: add an existing song to an album\nl: add a new audiobook\n\np: create a new playlist from existing songs and audiobooks\n-: delete a playlist\n\ns: save playlists, albums, songs and audiobooks into the concerned files\n\nS: List all your saved songs\nB: List all your saved audiobooks\nA: List all your saved albums\nP: List all your saved playlists\n\nPS: Print playlists sorted by their name\nPC: Print the content of a playlist\nAD: Print albums sorted by their date of release\nAG: Print albums sorted by their genre\nAC: Print the content of an album\n\nh: print this help screen\nq: quit the program\n"); + System.out.printf("c: add a new song\na: add a new album\n+: add an existing song to an album\nl: add a new audiobook\n\np: create a new playlist from existing songs and audiobooks\n-: delete a playlist\n\ns: save playlists, albums, songs and audiobooks into the concerned files\n\nS: List all your saved songs\nB: List all your saved audiobooks\nA: List all your saved albums\nP: List all your saved playlists\n\nPS: Print playlists sorted by their name\nPC: Print the content of a playlist\nAD: Print albums sorted by their date of release\nAG: Print albums sorted by their genre\nAC: Print the content of an album\nBA: Print audiobooks sorted by their author's name\n\nh: print this help screen\nq: quit the program\n"); break; case "q" : //quit @@ -717,6 +740,9 @@ public static void listAlbumsByGenre(){ case "AC": //display content of a chosen album contentOfAlbum(albums); break; + case "BA": //display audiobooks sorted by authors + listAudioBooksByAuthor(); + break; default : System.out.println("Unknown command. Type h for help."); } |