/* * Name : Album * * Description : The Album class is used to create albums containing songs added after its creation and the creation of the songs * * Version : 1.0 * * Date : 28/12/2020 * * Copyright : Aimeric ADJUTOR */ import java.util.*; import java.io.Serializable; /** * The album class is used to create albums containing songs added after its creation and the creation of the songs. * * @version 1.0 * * @see Song * @author Aimeric ADJUTOR */ public class Album implements Serializable { private static final long serialVersionUID = -8678385322105507976L; private int id, duration; private Date date; private String title, artist; private ArrayList songs = new ArrayList(); /** * Constructor method. * * @param title String * @param duration int, calculated with the actual duration of the object's songs * @param artist String * @param date Date * @param songs ArrayList * * @see MusicalElement * * @author Aimeric ADJUTOR * */ public Album(String title, int duration, String artist, Date date, ArrayList songs) { this.title=title; this.duration=this.getDuration(); this.artist=artist; this.date=date; this.songs=songs; } /** * This method is used to give the id of the album. * * @return It returns the id, which is an int. * * @author Aimeric ADJUTOR * */ public int getId(){return id;} /** * This method is used to give the title of the album. * * @return It returns the title, which is a String. * * @author Aimeric ADJUTOR * */ public String getTitle(){return title;} /** * This method is used to give the duration of the album. * It calculates it by getting the duration of each songs. * * @return It returns the total duration, which is an int. * * @see Song#getDuration * * @author Aimeric ADJUTOR * */ public int getDuration(){ for (Song s : songs) {duration+=s.getDuration();} //increase with each song's getDuration() return duration; } /** * This method is used to give the artist of the album. * * @return It returns the artist, which is a String. * * @author Aimeric ADJUTOR * */ public String getArtist(){return artist;} /** * This method is used to give the date of release of the album. * * @return It returns the date, which is a Date. * * @author Aimeric ADJUTOR * */ public Date getDate(){return date;} /** * This method is used to print the each songs contained in the songs attribute of the album. * * @author Aimeric ADJUTOR * */ public void getSongs(){ for ( Song s : songs ){ System.out.println(s); } } /** * This method is used for the AG command in jMusicHub. * It's searching for the irst song in the ArrayList songs and takes it's name. * * @return The genre, a Genre object, is returned. * * @see Song#getGenre * @see jMusicHub#listAlbumsByGenre * * @author Aimeric ADJUTOR * */ public String getGenre(){ //used for AG Song firstSong=this.songs.get(0); String firstSongGenre = firstSong.getGenre(); return firstSongGenre; }; /** * Basic method to set the id of the album. * * @param id int * * @author Aimeric ADJUTOR * */ public void setId(int id){this.id=id;} /** * Basic method to set the title of the album. * * @param title String * * @author Aimeric ADJUTOR * */ public void setTitle(String title){this.title=title;} /** * Basic method to set the artist of the album. * * @param artist String * * @author Aimeric ADJUTOR * */ public void setArtist(String artist){this.artist=artist;} /** * Basic method to set the date of the album. * * @param date Date * * @author Aimeric ADJUTOR * */ public void setDate(Date date){this.date=date;} /** * Mehtod to add songs, of the Song class, to the album's arrayList. * * @param song Song * * @author Aimeric ADJUTOR * */ public void addSong(Song song){ this.songs.add(song); } /** * Basic method to "configure" what does a print of this object actually does. * * @return String, using the object's methods * * @author Aimeric ADJUTOR * */ public String toString() { return "Id : "+getId()+"\nTitle : "+getTitle()+"\nDuration : "+getDuration()+"\nArtist : "+getArtist()+"\nDate of release : "+getDate(); } }