aboutsummaryrefslogtreecommitdiff
path: root/jMusicHub.java
diff options
context:
space:
mode:
Diffstat (limited to 'jMusicHub.java')
-rw-r--r--jMusicHub.java93
1 files changed, 85 insertions, 8 deletions
diff --git a/jMusicHub.java b/jMusicHub.java
index c70c9b8..90e5e44 100644
--- a/jMusicHub.java
+++ b/jMusicHub.java
@@ -1,6 +1,20 @@
import java.util.*;
import java.io.*;
import java.text.*;
+/* TO DO :
+ * Creating a playlist with musics and audiobooks (p)
+ * Deleting playlists (-)
+ * Printing the songs of a chosen album
+ * Printing album sorted by date of release
+ * Printing album sorted by its songs genre
+ * Printing plyalist sorted by name
+ * Printing audiobooks sorted by author
+ * Generating the javadoc
+ * Doing the UML Diagramm
+ * Doing the report
+ * Sending in the whole thing
+ * */
+
/** <h1>jMusicHub</h1>
*
@@ -79,7 +93,7 @@ public class jMusicHub {
Category category = Category.valueOf(choosedCategory);
System.out.println("");
- System.out.println("Do you confirm the addition of the following song ?");
+ System.out.println("Do you confirm the addition of the following audiobook ?");
System.out.println("Title : " + title);
System.out.println("Duration : " + duration);
System.out.println("Content path : " + content);
@@ -100,7 +114,7 @@ public class jMusicHub {
}
/** <h2>addAlbum</h2>
- * addAlbum is used to add songs thanks to the "a" option
+ * addAlbum is used to add albums thanks to the "a" option
* @param scan Scanner Object
*/
public static Album addAlbum(Scanner scan){
@@ -117,7 +131,7 @@ public class jMusicHub {
Date date = df.parse(dateString);
System.out.println("");
- System.out.println("Do you confirm the addition of the following song ?");
+ System.out.println("Do you confirm the addition of the following album ?");
System.out.println("Title : " + title);
System.out.println("Artist : " + artist);
System.out.println("Date of release : " + date);
@@ -140,6 +154,64 @@ public class jMusicHub {
}
}
+ /** <h2>addPlaylist</h2>
+ * addPlaylist is used to add playlist thanks to the "p" option
+ * @param scan Scanner Object
+ */
+ public static Playlist addPlaylist(Scanner scan, ArrayList<Song> songs, ArrayList<AudioBook> audiobooks){
+ String userInput;
+ System.out.println("Adding a playlist...");
+ System.out.printf("Name : ");
+ String name = scan.nextLine();
+ ArrayList<Song> playlistSongs = new ArrayList<Song>();
+ ArrayList<AudioBook> playlistAudioBooks = new ArrayList<AudioBook>();
+ System.out.println("\n[You'll have to add each song or audiobook element by element]\n");
+
+ do {
+ System.out.println("What do you want to add to this playlist ?\n[(s)ong/(a)udiobook/(q)uit]\n");
+ userInput = scan.nextLine();
+ switch(userInput) {
+ case "s" :
+ System.out.printf("Song ID : ");
+ int songId = scan.nextInt();
+ String trash = scan.nextLine();
+ for (Song s : songs) { //looking for the right song
+ if ( songId == s.getId() ) {
+ playlistSongs.add(s);
+ }
+ }
+ break;
+ case "a" :
+ System.out.printf("Album ID : ");
+ int audiobookId = scan.nextInt();
+ trash = scan.nextLine();
+ for (AudioBook a : audiobooks) { //looking for the right song
+ if ( audiobookId == a.getId() ) {
+ playlistAudioBooks.add(a);
+ }
+ }
+ break;
+ default :
+ System.out.println("Unknown command.");
+ }
+
+ } while(!userInput.equals("q"));
+
+ System.out.println("Do you confirm the addition of the following playlist ?");
+ System.out.println("Name : " + name);
+ System.out.println("[Y/n]");
+ String confirm = scan.nextLine();
+
+ if (confirm.equalsIgnoreCase("Y")){ //if the user is ok with what he typed, create a playlist obj
+ Playlist newPlaylist = new Playlist(name, playlistSongs, playlistAudioBooks);
+ return newPlaylist;
+ } else {
+ System.out.println("Aborting...");
+ System.out.println("");
+ return null;
+ }
+ }
+
/**<h2>save</h2>
* save is used by the command "s"
* It is used to serialize (save) arrays of a list into the type's file.i
@@ -306,8 +378,8 @@ public class jMusicHub {
}
}
- public static void addSongs(Scanner scan, ArrayList<Album> albums){
- System.out.println("Adding a existing song to an existing album");
+ public static void addSongToAlbum(Scanner scan, ArrayList<Album> albums, ArrayList<Song> songs){
+ System.out.println("Adding a existing song to an existing album...");
System.out.printf("Song's ID : ");
int songId = scan.nextInt();
System.out.printf("Album's ID : ");
@@ -315,9 +387,14 @@ public class jMusicHub {
int albumId = scan.nextInt();
trash = scan.nextLine();
- for (Album a : albums) {
+ for (Album a : albums) { //looking for the right album
if ( albumId == a.getId() ) {
- System.out.println(a);
+ for ( Song s : songs ){ //as we've found the right album, we're now looking for the right song.
+ if ( songId == s.getId() ){
+ System.out.println("\nAdding "+s.getTitle()+" from "+s.getArtist()+" to "+a.getTitle()+"\n");
+ a.addSong(s);
+ }
+ }
}
}
}
@@ -393,7 +470,7 @@ public class jMusicHub {
break;
case "+": //add an existing song to an album
- addSongs(scan, albums);
+ addSongToAlbum(scan, albums, songs);
break;
case "l": //add a new audiobook
try { //If something goes wrong, abort