From 3b58bb1f300f0b8a951ccdcf1143d2d99612cc92 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 28 Dec 2020 12:56:51 +0100 Subject: Print album sorted by date method --- jMusicHub.java | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/jMusicHub.java b/jMusicHub.java index f25fb46..cd3d3eb 100644 --- a/jMusicHub.java +++ b/jMusicHub.java @@ -2,7 +2,6 @@ import java.util.*; import java.io.*; import java.text.*; /* TO DO : - * Printing the songs of a chosen album * Printing album sorted by date of release * Printing album sorted by its songs genre * Printing audiobooks sorted by author @@ -343,6 +342,28 @@ public class jMusicHub { catch (ClassNotFoundException ex) {System.out.println("ClassNotFoundException is caught");} } + public static void listAlbumsByDate(){ + String filename = "albums"; + try { + // Reading the object from a file + FileInputStream file = new FileInputStream(filename); + ObjectInputStream in = new ObjectInputStream(file); + + @SuppressWarnings("unchecked") + ArrayList albums = (ArrayList)in.readObject(); + in.close(); + file.close(); + + Collections.sort(albums, Comparator.comparing(Album::getDate)); + + System.out.println("\nSaved "+filename+", sorted by name :\n"); + for (Album a : albums ){ + System.out.println(a); + } + } + catch (IOException ex) {System.out.println(filename+ " file missing.");} + catch (ClassNotFoundException ex) {System.out.println("ClassNotFoundException is caught");} + } /**

extract

* Extract is used to print the content of the files and put them in the ArrayList used to add elements. @@ -536,7 +557,7 @@ public class jMusicHub { 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\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\nAC: Print the content of an album\n\nh: print this help screen\nq: quit the program\n"); break; case "q" : //quit @@ -663,10 +684,13 @@ public class jMusicHub { case "PS": //print playlists sorted by their name listPlaylistsByName(); break; - case "PC": + case "PC": //display content of a chosen playlist contentOfPlaylist(playlists); break; - case "AC": + case "AD" : + listAlbumsByDate(); + break; + case "AC": //display content of a chosen album contentOfAlbum(albums); break; default : -- cgit v1.2.3