diff options
author | Clyhtsuriva <aimeric@adjutor.xyz> | 2020-12-28 13:46:17 +0100 |
---|---|---|
committer | Clyhtsuriva <aimeric@adjutor.xyz> | 2020-12-28 13:46:17 +0100 |
commit | cdb478d05fb5ece0533601a43bd538966d05f14d (patch) | |
tree | 3b1c1698bcfd4e42f9fca78c9cfd82ba7013cf80 | |
parent | 61768eade51a08d0036156a05bd83311dc1b6299 (diff) |
Method to show audiobooks sorted by author
-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."); } |