Question

Create two classes. Song. Should include the name of the song and the artist Playlist. Should...

Create two classes.

Song. Should include the name of the song and the artist

Playlist. Should include a list of song objects from the above class, a title for the list and a description of the list. Specific method requirements below.

Functionality

You should be able to print both a song and a playlist. Formatting should follow the below examples EXACTLY. I should be able to print a so11ng or a playlist by calling the standard python print function.

Format for printing a song should be

Format for printing a play list should be

Title: <song title>
Artist: <artist>

Example.

Title: Bad Guy

Artist: Billie Eilish

Playlist: <playlist title>
Description: <playlist description>
Songs:

<title1>

<title2>

.

<titleN>

Example.

Playlist: Country Gooderns
Description: Classic country songs
Songs:
Coal Miner’s Daughter
Walk the Line

Friends in Low Places

Stand by your Man

The play list class should allow adding songs through an addSong method. Duplicate song names are not allowed and should result in an error message back to the user. Songs with the same title but different case would be considered duplicates. Walk The Line would be considered a duplicate of WALK THE line.

The play list class should allow searching to see if a song exists through a songFound method. This search can be done on an exact match of the title (upper or lower case allowed). If I searched for walk THE Line in the above list, it would find a match. Result should be returned as a Boolean.

The play list class should allow randomizing the order of the songs in the list through a shuffleList method. Songs would normally be included in the order they were added. If I call the randomize process, the playlist should be shuffled into a random order of songs.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have created all the classes in a single file and included main method to test the methods in classes. Please feel free to change the main method in any way required

Below are the screenshots of the file:

Below is the code for the same:

from random import shuffle


class Song:
    def __init__(self, name, artist):
        self.name = name
        self.artist = artist

    # Method to print a Song
    def print(self):
        print("Title: ", self.name)
        print("Artist: ", self.artist)


class Playlist:
    def __init__(self, title, desc):
        self.title = title
        self.desc = desc
        self.songs = []

    # Method to add a Song
    def addSong(self, newSong):
        # Checking for duplicate songs even if the case is different
        for song in self.songs:
            if song.name.upper() == newSong.name.upper():
                return "Error: Song with title '" + newSong.name + "' already exists"

        # If it is not a duplicate add to the list
        self.songs.append(newSong)
        return "Successfully added '" + newSong.name + "'"

    # Method to search a song
    def songFound(self, songTitle):
        for song in self.songs:
            if song.name.upper() == songTitle.upper():
                return True
        return False

    # Method to shuffle the list of songs to change their order
    def shuffleList(self):
        shuffle(self.songs)

    # Method to print the Playlist
    def print(self):
        print("Playlist: ", self.title)
        print("Description: ", self.desc)
        print("Songs:")
        for song in self.songs:
            print(song.name)


def main():
    # Creating Song objects
    s1 = Song("Bad Guy", "Billie Eilish")
    s2 = Song("Coal Miner's Daughter", "Billie Donald")
    s3 = Song("Walk the Line", "Cathy")
    s4 = Song("Friends in low places", "John")

    # Creating a Playlist
    p1 = Playlist("Country Gooderns", "Classic Country Songs")

    # Adding songs to the playlist
    print(p1.addSong(s1))
    print(p1.addSong(s2))
    print(p1.addSong(s3))
    print(p1.addSong(s4))
    # Adding a song which already exists
    print(p1.addSong(Song("bad guy", "Bowden")))

    # Printing the Playlist
    p1.print()

    # Finding the song in the Playlist
    print(p1.songFound("Bad Guy"))
    # Shuffling the songs
    p1.shuffleList()
    # Printing the sings after shuffling
    p1.print()


if __name__ == "__main__":
    main()

Below is the screenshot of sample output:

Please feel free to change the output in a way required. Hope this helps you and also hoping for a positive review

Add a comment
Know the answer?
Add Answer to:
Create two classes. Song. Should include the name of the song and the artist Playlist. Should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp,...

    I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor copy constructor destructor addSong(song tune) adds a single node to the front of the linked list no return value displayList() displays the linked list as formatted in the example below no return value overloaded assignment operator A description of all of these functions is available in the textbook's...

  • (1) Create two files to submit: Song.java - Class definition MainClass.java - Contains main() method (2)...

    (1) Create two files to submit: Song.java - Class definition MainClass.java - Contains main() method (2) Build the Song class in Song.java with the following specifications: Private fields String songTitle String songArtist int secDuration Initialize String fields to "Not defined" and numeric to 0. Create overloaded constructor to allow passing of 1 argument (title), 2 (title, artist) and 3 arguments (title, artist, duration). Create public member method printSongInfo () with output formatted as below: Title: Born in the USA Artist:...

  • Introduction In this final programming exercise, you'll get a chance to put together many of the...

    Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...

  • THE ENTIRE CODE SHOULD BE IN JAVA Playlist (output linked list) Given main(), complete the SongNode...

    THE ENTIRE CODE SHOULD BE IN JAVA Playlist (output linked list) Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers...

  • public class Song { private String title; private String artist; private int duration; public Song() {...

    public class Song { private String title; private String artist; private int duration; public Song() { this("", "", 0, 0); } public Song(String t, String a, int m, int s) { title = t; artist = a; duration = m * 60 + s; } public String getTitle() { return title; } public String getArtist() { return artist; } public int getDuration() { return duration; } public int getMinutes() { return duration / 60; } public int getSeconds() { return...

  • JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the...

    JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones...

  • You will be building a linked list. Make sure to keep track of both the head and tail nodes.

    Ch 8 Program: Playlist (Java)You will be building a linked list. Make sure to keep track of both the head and tail nodes.(1) Create two files to submit.SongEntry.java - Class declarationPlaylist.java - Contains main() methodBuild the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps.Private fieldsString uniqueID - Initialized to "none" in default constructorstring songName - Initialized to "none" in default constructorstring artistName - Initialized to "none"...

  • Many of us have large digital music collections that are not always very well organized. It...

    Many of us have large digital music collections that are not always very well organized. It would be nice to have a program that would manipulate our music collection based on attributes such as artist, album title, song title, genre, song length, number times played, and rating. For this assignment you will write a basic digital music manager (DMM). Your DMM program must have a text-based interface which allows the user to select from a main menu of options including:...

  • Write the following method definitions for the DLL class: (5 pt) void push(string t, string a,...

    Write the following method definitions for the DLL class: (5 pt) void push(string t, string a, int m, int s); This pushes a new node onto the end of the list. If there are no nodes in the list, it creates the first node and adds it. Otherwise it places a new node onto the end of the list. t is the song’s title,a is the song’s artist, m is the number of minutes the song runs for, and s...

  • Please use C programming to write the code to solve the following problem. Also, please use the i...

    Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT