aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2020-12-24 06:48:40 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2020-12-24 06:48:40 +0100
commitf7a696ffc2247de6377c0e080c44e54b98fb123d (patch)
treee8a34eff518396fe80f38c585abaaae10e8bfd3b
parentbec74db10232efaa6d1456df4d01924f0313a0e9 (diff)
Finishing album and starting playlists
-rw-r--r--Album.java6
-rw-r--r--Playlist.java19
-rw-r--r--jMusicHub.java93
3 files changed, 102 insertions, 16 deletions
diff --git a/Album.java b/Album.java
index 5035398..1dd193d 100644
--- a/Album.java
+++ b/Album.java
@@ -35,8 +35,12 @@ public class Album implements Serializable {
public void setArtist(){this.artist=artist;}
public void setDate(){this.date=date;}
+ public void addSong(Song song){
+ this.songs.add(song);
+ }
+
public String toString() {
- return "Id : "+getId()+"\nTitle : "+getTitle()+"\nDuration : "+getDuration()+"\nArtist : "+getArtist()+"\nDate of release : "+getDate()+"\nSongs : "+getSongs();
+ return "Id : "+getId()+"\nTitle : "+getTitle()+"\nDuration : "+getDuration()+"\nArtist : "+getArtist()+"\nDate of release : "+getDate();
}
}
diff --git a/Playlist.java b/Playlist.java
index 635f62a..03f412f 100644
--- a/Playlist.java
+++ b/Playlist.java
@@ -2,23 +2,28 @@ import java.util.ArrayList;
import java.io.Serializable;
public class Playlist implements Serializable {
+ private static final long serialVersionUID = 6021717365357635741L;
private int id;
private String name;
- private ArrayList<Song> content = new ArrayList<Song>();
+ private ArrayList<Song> songs = new ArrayList<Song>();
+ private ArrayList<AudioBook> audiobooks = new ArrayList<AudioBook>();
- public Playlist(int id, String name, ArrayList<Song> content) {
- this.id=id;
+ public Playlist(String name, ArrayList<Song> songs, ArrayList<AudioBook> audiobooks) {
this.name=name;
- this.content=content;
+ this.songs=songs;
+ this.audiobooks=audiobooks;
}
public int getId(){return id;}
public String getName(){return name;}
- public ArrayList<Song> getContent(){return content;}
+ public ArrayList<Song> getSongs(){return songs;}
+ public ArrayList<AudioBook> getAudioBooks(){return audiobooks;}
- public void setID(){this.id=id;}
+ public void setID(int id){this.id=id;}
public void setName(){this.name=name;}
-// public void setContent(){this.content=content;}
+ public String toString() {
+ return "Id : "+getId()+"\nName : "+getName();
+ }
}
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