aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jMusicHub.java32
1 files 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<Album> albums = (ArrayList<Album>)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");}
+ }
/**<h2>extract</h2>
* 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 :