PennTunes

Goal

Overiew

Like arrays, Java Lists allow us to store collections. However, they have useful features that arrays don't have. Most notably, methods. For example, Lists have methods for adding items, removing items,and searching for items. In Java, a List is an interface. One popular class that implements the List interface is an ArrayList (with effiecient "random access" and as the ability to grow and shrink dynamically). In this lab we experiment with ArrayList that are parameterized i.e. ArrayList <E> where E is type of Element the ArrayList will contain. In Java lingo ArrayList <E> is known as using ArrayList with Generics.

Details

You are a programmer for the company called PennTunes. Your task is to create a Playlist class that can create playlists. Each playlist has a name and can hold any number of songs and can perform some operations such as adding a song, removing, searching for a song etc.

Things you need

Methods to write in Playlist class (Submit Playlist.java)

Some methods are already implemented for you. The following methods are to be implemented (Note: make all methods public):

Interactions

Sample interactions are as follows ( penntunes.hist to save typing):

> Song s1 = new Song("Yellow", "Cold Play", 2.4);
> Song s2 = new Song("Clocks", "Cold Play", 3.56);
> s2 //prints song state due to toString() in Song class
song: Clocks, artist: Cold Play, playTime: 3.56
> Playlist p = new Playlist("ColdPlayHits");
> p.addSong(s1)
true
> p.addSong(s2)
true
> p.totalSongs()
2
-----------------------------------------------------
> p.playlistTime()
5.96
> p.removeSong(s2)
true
> p.totalSongs()
1
> p.addSong(s2)
true

-----------------------------------------------------
> p.isSongInPlaylist("clocks") //case does not matter in search string
true
> p.songsByArtist( "Cold Play")
song: Clocks, artist: Cold Play, playTime: 3.56
song: Yellow, artist: Cold Play, playTime: 2.4
> p.songsByArtist("Grease Monkey")
No such artist
----------------------------------------------------
> Song s3 = new Song("Around the Sun", "REM", 4.30);
> Playlist favorites = new Playlist("favorites");
> favorites.addSong(s3)
true
> favorites.addSong(s1)
true
> favorites.addSongsFrom(p);
> favorites.getList() //getList() returns List<Song> type and toString() in ArrayList class prints the list contents
[song: Around the Sun, artist: REM, playTime: 4.3, song: Yellow, artist: Cold Play, playTime: 2.4, song: Yellow, artist: Cold Play, playTime: 2.4, song: Clocks, artist: Cold Play, playTime: 3.56]

Note: addSongsFrom could be better implemented to avoid duplicate entries of the same song object

----------------------------------------------------