diff options
author | Clyhtsuriva <aimeric@adjutor.xyz> | 2020-12-28 12:39:16 +0100 |
---|---|---|
committer | Clyhtsuriva <aimeric@adjutor.xyz> | 2020-12-28 12:39:16 +0100 |
commit | b3ed778f6452211bc4070ba7644ea3247ad8f234 (patch) | |
tree | ffec85357c5b048a2ec2c3ac887c88117cc89828 | |
parent | b5072cf8159adb16ff1826dce27bccb7ab41c141 (diff) |
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..
-rw-r--r-- | Playlist.java | 13 | ||||
-rw-r--r-- | albums | bin | 673 -> 962 bytes | |||
-rw-r--r-- | audiobooks | bin | 297 -> 670 bytes | |||
-rw-r--r-- | jMusicHub.java | 68 | ||||
-rw-r--r-- | playlists | bin | 968 -> 1140 bytes | |||
-rwxr-xr-x | run | 4 | ||||
-rw-r--r-- | songs | bin | 379 -> 1474 bytes |
7 files changed, 72 insertions, 13 deletions
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<Song> getSongs(){return songs;} - public ArrayList<AudioBook> 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;} Binary files differBinary files differdiff --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<Song>(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<AudioBook>(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<Album>(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<Playlist>(playlists); default : @@ -457,6 +478,23 @@ public class jMusicHub { return playlists; } + public static void contentOfPlaylist(ArrayList<Playlist> 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<Song> 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."); } Binary files differ@@ -0,0 +1,4 @@ +#!/bin/bash +#coding: utf-8 + +javac jMusicHub.java && java jMusicHub Binary files differ |