Ask Question
11 March, 07:47

Write the definition of a class Play List Entry containing:

A) An instance variable title of type string, initialized to the empty string.

B) An instance variable artist of type string, initialized to the empty string.

C) An instance variable play count of type int, initialized to 0.

D) In addition, your Play List class definition should provide an appropriately named "get" method and "set" method for each of these.

E) No constructor need be defined.

+4
Answers (1)
  1. 11 March, 08:26
    0
    class PlayListEntry:

    def __init__ (self):

    self._title = ''

    self._artist = ''

    self._play_count = 0

    @property

    def get_title (self):

    return self._title

    @get_title. setter

    def set_title (self, title):

    self._title = title

    @property

    def get_artist (self):

    return self._artist

    @get_artist. setter

    def set_artist (self, artist):

    self._artist = artist

    @property

    def get_play_count (self):

    return self._play_count

    @get_play_count. setter

    def set_play_count (self, play_count):

    self._play_count = play_count

    Explanation:

    The above code is written in Python Programming Language. A class called PlayListEntry is defined with getter and setter methods. In this solution, the property decorator was used to define the getter methods and the setter method uses setter attribute of the getter method.

    Notice that the instance variables of the class is preceded by an underscore. This is because I want the attributes of the class to be private. By making attributes of a class private, I mean that you cannot have a direct access to the attributes of the class. This concept an implementation of object oriented programming called Encapsulation.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write the definition of a class Play List Entry containing: A) An instance variable title of type string, initialized to the empty string. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers