I am writing a basic music app for my school. What our teacher asked from us is that wee need to create three classes; Song, PlayList and MusicCollection. A play list object contains songs and music collection contains play lists.I write my Song class and also a big part of my PlayList class. But there are two methods that I don't know very well. One is sortByName and the other is sortByPlayingTime. I need to use collections and I write something until now but it is not working. Can you have a look?
public class PlayList {
private String playListName;
private ArrayList<Song> songsPlayList = new ArrayList<>();
public PlayList(String playListName) {
this.playListName = playListName;
}
public void addSong(Song songObject){
songsPlayList.add(songObject);
}
public void removeSong(Song songObject) {
songsPlayList.remove(songObject);
}
public void countOfPlaylist(){
System.out.println("You have " + songsPlayList.size() + " songs on your list!");
}
public void displayPlayList(){
for (int i =0;i<songsPlayList.size();i++){
System.out.println((i+1) + ". " + songsPlayList.get(i));
}
}
public void sortByName(){
System.out.println("You can see your list as sorted by name.\n");
Collections.sort(song); //this code give an error!
for (Song temp : songsPlayList){
System.out.println(temp);
}
}
public void sortByPlayingTime(){
System.out.println("Your playlist sorted by playing time.");
//I stock here.
}
Also with my MusicCollection class I need to do the same thing. It was easy to add a song to a play list but now I need to choose (or say) which play list I need to add a song. I write my methods but not define yet. I need your help :)
Here is my MusicCollection class:
public class MusicCollection {
private String musicCollectionName;
private ArrayList<PlayList> collection = new ArrayList<>();
public MusicCollection(String musicCollectionName) {
this.musicCollectionName = musicCollectionName;
}
public void addSongToPlayList(String playListName,Song songObject){
}
public void removeSongFormPlaylist (String playListName, Song songObject){
}
public void addPlayList (PlayList playlistObject){
}
public void removePlayList (PlayList playlistObject){
}
public int countOfPlaylistsInCollection(){
return 0;
}
public int countsOfSongsInPlayList (String playlistName){
return 0;
}
public void displayPlayListInCollection(){
}
public void displaySongsFromPlaylist (String playlistName){
}
}