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.. --- Playlist.java | 13 +++++++++-- albums | Bin 673 -> 962 bytes audiobooks | Bin 297 -> 670 bytes jMusicHub.java | 68 +++++++++++++++++++++++++++++++++++++++++++++++---------- playlists | Bin 968 -> 1140 bytes run | 4 ++++ songs | Bin 379 -> 1474 bytes 7 files changed, 72 insertions(+), 13 deletions(-) create mode 100755 run diff --git a/Playlist.java b/Playlist.java index 990aa26..8374c77 100644 --- a/Playlist.java +++ b/Playlist.java @@ -17,8 +17,17 @@ public class Playlist implements Serializable { public int getId(){return id;} public String getName(){return name.toUpperCase();} //using toUpperCase method because the way I sort by name sort he upper case then the lower case, which is inconvenient. - public ArrayList getSongs(){return songs;} - public ArrayList getAudioBooks(){return audiobooks;} + public void getSongs(){ + for ( Song s : songs ){ + System.out.println(s); + } + } + public void getAudioBooks(){ + for (AudioBook b : audiobooks ){ + System.out.println(b); + } + + } public void setId(int id){this.id=id;} public void setName(){this.name=name;} diff --git a/albums b/albums index e72f50b..7fd7df7 100644 Binary files a/albums and b/albums differ diff --git a/audiobooks b/audiobooks index da41cf0..1e73597 100644 Binary files a/audiobooks and b/audiobooks differ 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."); } diff --git a/playlists b/playlists index e201e98..7ea07a0 100644 Binary files a/playlists and b/playlists differ diff --git a/run b/run new file mode 100755 index 0000000..528673d --- /dev/null +++ b/run @@ -0,0 +1,4 @@ +#!/bin/bash +#coding: utf-8 + +javac jMusicHub.java && java jMusicHub diff --git a/songs b/songs index 2208b77..d0de77c 100644 Binary files a/songs and b/songs differ -- cgit v1.2.3