From b3ed778f6452211bc4070ba7644ea3247ad8f234 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 28 Dec 2020 12:39:16 +0100 Subject: Repairing playlist An error occured when no playlists were found AND we wanted to create one. Also populated the objects files to meet the specs of the teach. Creating a run command, might delete later.. --- jMusicHub.java | 68 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 11 deletions(-) (limited to 'jMusicHub.java') diff --git a/jMusicHub.java b/jMusicHub.java index 715f85f..985a6a2 100644 --- a/jMusicHub.java +++ b/jMusicHub.java @@ -309,6 +309,7 @@ public class jMusicHub { for (Playlist p : playlists ){ System.out.println(p); } + break; } @@ -363,7 +364,12 @@ public class jMusicHub { in.close(); file.close(); - listById("songs"); +// listById("songs"); + int songCount=0; + for ( Song s : songs ){ + songCount+=1; + } + System.out.println("Extracted songs : "+songCount); return new ArrayList(songs); case "audiobooks" : @@ -373,7 +379,12 @@ public class jMusicHub { in.close(); file.close(); - listById("audiobooks"); +// listById("audiobooks"); + int bookCount=0; + for ( AudioBook b : audiobooks ){ + bookCount+=1; + } + System.out.println("Exctracted audiobooks : "+bookCount); return new ArrayList(audiobooks); case "albums" : @@ -383,7 +394,12 @@ public class jMusicHub { in.close(); file.close(); - listById("albums"); +// listById("albums"); + int albumCount=0; + for ( Album a : albums ){ + albumCount+=1; + } + System.out.println("Extracted albums : "+albumCount); return new ArrayList(albums); case "playlists" : @@ -393,7 +409,12 @@ public class jMusicHub { in.close(); file.close(); - listById("playlists"); +// listById("playlists"); + int playlistCount=0; + for ( Playlist p : playlists ){ + playlistCount+=1; + } + System.out.println("Extracted playlists : "+playlistCount); return new ArrayList(playlists); default : @@ -457,6 +478,23 @@ public class jMusicHub { return playlists; } + public static void contentOfPlaylist(ArrayList playlists){ + Scanner scan = new Scanner(System.in); + listById("playlists"); + System.out.println("\nWhich one do you want to see ?"); + System.out.printf("Playlist's ID : "); + int playlistId = scan.nextInt(); + String trash = scan.nextLine(); + for ( Playlist p : playlists ){ + if ( playlistId == p.getId() ){ + System.out.println("\nSongs : \n"); + p.getSongs(); + System.out.println("\nAudioBooks : \n"); + p.getAudioBooks(); + } + } + } + public jMusicHub() { System.out.println("Welcome to the jMusicHub !\n"); @@ -464,7 +502,7 @@ public class jMusicHub { Scanner scan = new Scanner(System.in); String userInput; //Used to get the user's inputs. - System.out.println("Extraction beginning..."); + System.out.println("Extraction beginning...\n"); @SuppressWarnings("unchecked") ArrayList songs = extract("songs"); @SuppressWarnings("unchecked") @@ -477,12 +515,13 @@ public class jMusicHub { System.out.println("\nExtraction done."); do { - System.out.println("What do you want to do? [h for help]"); + System.out.println("\nWhat do you want to do? [h for help]"); userInput = scan.nextLine(); + System.out.println(""); 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\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\n\nh: print this help screen\nq: quit the program\n"); break; case "q" : //quit @@ -556,9 +595,13 @@ public class jMusicHub { Playlist newPlaylist=addPlaylist(scan, songs, audiobooks); if (newPlaylist != null){ int playlistsSize = playlists.size(); - Playlist lastObject=playlists.get(playlistsSize-1); - int idOfLastObject = lastObject.getId(); - newPlaylist.setId(idOfLastObject+1); + if ( playlistsSize != 0){ + Playlist lastObject=playlists.get(playlistsSize-1); + int idOfLastObject = lastObject.getId(); + newPlaylist.setId(idOfLastObject+1); + } else { + newPlaylist.setId(playlistsSize); + } playlists.add(newPlaylist); System.out.println("\nActual content of your list (you must save it (s) to do anything else with them) :"); for (Playlist iPlaylist : playlists){ @@ -602,9 +645,12 @@ public class jMusicHub { case "P": //print playlists sorted by id listById("playlists"); break; - case "PS": //print playslists sorted by their name + case "PS": //print playlists sorted by their name listPlaylistsByName(); break; + case "PC": + contentOfPlaylist(playlists); + break; default : System.out.println("Unknown command. Type h for help."); } -- cgit v1.2.3