In this project, you will experiment with building your own Python classes. Many of you have
music files on your computer and organize them into playlists.
You will build classes to represent your music files and playlists to organize them.
You may do this project with a partner. If you choose to work with a partner, please only submit one copy of the code with both names written in each of the Python files as a comment.
Song
class in song.py
such that:
Song
object contains the artist, album title, song title, mp3 file name, and genre.
Song
class provides accessor and mutator methods for all instance variables.
Song
object is printed, it shows the artist, album title, and song title. For example, if you print the song "Just Dance" in The Fame by Lady Gaga, you should see:
Just Dance in The Fame by Lady Gaga
Playlist
class in playlist.py
such that:
Song
objects, and an indication whether the playlist is to be played in a random order.
Playlist
class provides accessor and mutator methods for the instance variables you use for the name, list of songs, and random-play indication.
Playlist
object is printed, it shows the playlist name and all the songs in the playlist. For example, if you print the playlist whose name is "Lady Gaga Mix" and which contains two songs: "Just Dance" in The Fame by Lady Gaga and "Americano" in Born This Way by Lady Gaga, you should see:
Playlist: Lady Gaga Mix
Just Dance in The Fame by Lady Gaga
Americano in Born This Way by Lady Gaga
Playlist
class provides a method called nextSong
which returns the next Song
object to play in the playlist. If the playlist is played in the original order, it should return the next song in the list. If the playlist is played in a random order, it should return a song that has not been played yet. It should only repeat a song if all songs in the playlist have been played. This ensures that the playlist does not keep returning same two songs over and over again.Notes and considerations
nextSong
method should return the first song in the original list of songs. If the play order is changed from non-random to random, it should start returning songs in a random order as described above.
nextSong
method should return the first song in the new list of songs. If the player order is random, it should return a random song in the new list of songs.Example of a playlist of 3 songs (A, B, C)
Non-random order | Random Order | ||
Correct | Incorrect | Suspicious | |
Song A Song B Song C Song A Song B Song C Song A Song B Song C . . . |
Song C Song B Song A Song B Song A Song C Song C Song A Song B . . . (Notice how each song appears only once in songs 1-3, 4-6, etc.) |
Song C Song B Song C Song A Song B Song A Song B Song C Song A . . . (Notice how Song C reappears before all 3 songs are played.) |
Song B Song C Song A Song B Song C Song A Song B Song C Song A . . . (Notice how the same permutation (B, C, A) keeps repeating.) |
sample.py
. (Make sure there are at least 5 unique songs in your examples.)
NOTE: This only works on Macs (Mac OS X).
play.py
into the same directory.
Terminal
by typing "Terminal" (without quotation marks) in Spotlight (the magnifying class at the top right corner of the screen).
cd
.
python
to enter the Python shell.
from play import *
into the Python shell.
play(myPlaylist1)
into the Python shell (or any other playlists you created in sample.py
), and enjoy your music!
ctrl-c
(CTRL key and C key at the same time) to stop playing the playlist.
You will be submitting your code using Moodle; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit the following files:
Song
class.Playlist
class.You will earn one point for each of the following accomplishments:
Song
class.
Song
class.
Song
class.
Song
class respond to a blank string by printing an error message and not changing the instance variable.
Song
class provides a special method such that you can convert a Song
object into a string, which would aautomatically be used for printing.
Playlist
class.
Playlist
class.
Playlist
class.
Playlist
class responds to a blank string by printing an error message and not changing the instance variable.
Playlist
class provides a special method such that you can convert a Playlist
object into a string, which would be automatically used for printing.
nextSong
method returns a Song
object.
nextSong
method returns the correct Song
object when the Playlist
is set to non-random order.
nextSong
method returns the correct Song
object when the Playlist
is set to random order.
nextSong
method does not return the same Song
object until all Song
objects have been returned by the nextSong
.
Song
and Playlist
classes.
Song
and Playlist
classes.
nextSong
method in the Playlist
class.
Song
objects in sample.py
.
Playlist
objects with different names and songs in sample.py
.