From ec126de053cd1343e0c5778a56ea58045d0e3170 Mon Sep 17 00:00:00 2001 From: Masfehico Date: Mon, 7 Dec 2020 18:26:18 +0100 Subject: Big update Implementing the function to add songs. Cleaning a bit everywhere as well. --- Album.java | 4 +-- AudioBook.java | 4 +-- MusicalElement.java | 5 +-- Playlist.java | 4 +-- Song.java | 10 ++++-- jMusicHub.java | 88 +++++++++++++++++++++++++++++++++++++++++++++++++---- 6 files changed, 99 insertions(+), 16 deletions(-) diff --git a/Album.java b/Album.java index 8c7b809..e8766a3 100644 --- a/Album.java +++ b/Album.java @@ -4,9 +4,9 @@ public class Album { private int id, duration, date; private String title, artist; - private ArrayList songs = new ArrayList(); + private ArrayList songs = new ArrayList(); - public Album(int id, String title, int duration, String artist, int date, ArrayList songs) { + public Album(int id, String title, int duration, String artist, int date, ArrayList songs) { this.id=id; this.title=title; this.duration=duration; diff --git a/AudioBook.java b/AudioBook.java index 6502a32..03c6b0e 100644 --- a/AudioBook.java +++ b/AudioBook.java @@ -1,7 +1,7 @@ public class AudioBook extends MusicalElement { private String author, language, category; - public AudioBook(int id, String title, int duration, String content, String author, Language language, Category category) { - super(id, title, duration, content); + public AudioBook(String title, int duration, String content, String author, Language language, Category category) { + super(title, duration, content); this.author=author; this.language=language.name(); this.category=category.name(); diff --git a/MusicalElement.java b/MusicalElement.java index 1edd7eb..5c24641 100644 --- a/MusicalElement.java +++ b/MusicalElement.java @@ -9,10 +9,11 @@ class MusicalElement { //Our vars private int id, duration; private String title, content; + private static int idCount=0; - public MusicalElement(int id, String title, int duration, String content) { - this.id=id; + public MusicalElement(String title, int duration, String content) { + this.setId(idCount++); this.title=title; this.duration=duration; this.content=content; diff --git a/Playlist.java b/Playlist.java index b79f402..2e19822 100644 --- a/Playlist.java +++ b/Playlist.java @@ -4,9 +4,9 @@ public class Playlist { private int id; private String name; - private ArrayList content = new ArrayList(); + private ArrayList content = new ArrayList(); - public Playlist(int id, String name, ArrayList content) { + public Playlist(int id, String name, ArrayList content) { this.id=id; this.name=name; this.content=content; diff --git a/Song.java b/Song.java index c7556b1..c4d1fc3 100644 --- a/Song.java +++ b/Song.java @@ -1,7 +1,7 @@ public class Song extends MusicalElement { private String artist, genre; - public Song(int id, String title, int duration, String content, String artist, Genre genre) { - super(id, title, duration, content); + public Song(String title, int duration, String content, String artist, Genre genre) { + super(title, duration, content); this.artist=artist; this.genre=genre.name(); } @@ -10,4 +10,10 @@ public class Song extends MusicalElement { public String getGenre(){return genre;} public void setArtist(String artist){this.artist=artist;} public void setGenre(Genre genre){this.genre=genre.name();} + + public String toString() { + return getTitle()+";"+getDuration()+";"+getContent()+";"+artist+";"+genre; + } + + } diff --git a/jMusicHub.java b/jMusicHub.java index c95e1e6..0cb43b5 100644 --- a/jMusicHub.java +++ b/jMusicHub.java @@ -1,5 +1,4 @@ -import java.util.Scanner; - +import java.util.*; /**

jMusicHub

* @@ -13,16 +12,71 @@ import java.util.Scanner; public class jMusicHub { - public static void main(String[] args) { + /**

addSong

+ * add Song is used to add songs thanks to the "c" option + * @param scan Scanner Object + */ + public static Song addSong(Scanner scan){ + System.out.println("Adding a song..."); + System.out.printf("Title : "); + String title = scan.nextLine(); + System.out.printf("Duration (in seconds) : "); + int duration = scan.nextInt(); + System.out.printf("Content path : "); + String trash = scan.nextLine(); //Using this because the content scan is skippe after a nexInt + String content = scan.nextLine(); + System.out.printf("Artist : "); + String artist = scan.nextLine(); + System.out.printf("Genre (JAZZ, CLASSICAL, HIPHOP, ROCK, POP, RAP) : "); + String choosedGenre = scan.nextLine(); + choosedGenre = choosedGenre.toUpperCase(); + Genre genre = Genre.valueOf(choosedGenre); + System.out.println(""); - System.out.println("Welcome to the jMusicHub !"); + System.out.println("Do you confirm the addition of the following song ?"); + System.out.println("Title : " + title); + System.out.println("Duration : " + duration); + System.out.println("Content path : " + content); + System.out.println("Artist : " + artist); + System.out.println("Genre : " + genre); + System.out.println("[Y/n]"); + String confirm = scan.nextLine(); + + if (confirm.equalsIgnoreCase("Y")){ //if the user is ok with what he typed, create a song obj + Song newSong = new Song(title, duration, content, artist,genre); + return newSong; +// songs.add(newSong); + } else { + System.out.println("Aborting..."); + System.out.println(""); + return null; + } + } + + public jMusicHub() { + + System.out.println("Welcome to the jMusicHub !\n"); Scanner scan = new Scanner(System.in); String userInput; //Used to get the user's inputs. + ArrayList songs = new ArrayList(); + //used to temporarly save the songs before any "s" command + System.out.println("Starting extraction"); - //Here will be the process to extract the CSV files - System.out.println("Extraction done"); + //Here will be the process to extract the files +/* try { + FileOutputStream fos = new FileOutputStream(file); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(albums); + oos.close(); + fos.close(); + } + catch (IOException ioe) { + ioe.printStackTrace(); + return; + }*/ + System.out.println("Extraction done\n"); //Here will be the number of playlist, albums, songs and auidobook extracted do { @@ -35,8 +89,25 @@ public class jMusicHub { case "q" : System.out.println("Goodbye !"); break; + case "c": + try { //If something goes wrong, abort + Song newSong=addSong(scan); + if (newSong != null){ + songs.add(newSong); + System.out.println("Actual content of your songs list (you must save it (s) to do anything else with your songs) :"); + for (Song iSong : songs){ + System.out.println(iSong); + } + System.out.println(""); + + } + } catch (InputMismatchException | IllegalArgumentException e) { + System.out.println("You typed something wrong... I'm aborting.."); + System.out.println(""); + } break; + case "a": break; case "+": @@ -52,5 +123,10 @@ public class jMusicHub { } } while(!userInput.equals("q")); + + } + + public static void main(String[] args) { + new jMusicHub(); } } -- cgit v1.2.3