Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

python In this problem you will create two classes; one called Member and anothe

ID: 3718874 • Letter: P

Question

python

In this problem you will create two classes; one called Member and another called Band. Neither of these classes inherit each other this problem will use a technique called composition instead of inheritance. Each Member object will contain the following information: 1. Instrument type (for example, "guitar) 2. Player name (for example, "Susan") The Member cass will also contain the following methods (other than init 1. def getInstrument (self): 2. def getPlayer (self) 3. def setInstrument (self, instrument) 4. def setPlayer (self, player) 5. def (self): This method will return the instrument type This method will return the player's name This method will set the type of instrument to the new instrument type passed in This method will set the name of the player to the new player name passed in a. a. a. a. This method retums a string representation of the Member object (for example. str (Member ("guitar", "Susan")) would return the string "Susan plays guitar") a. 6. defeq (self, rhand) : a. This method overnides the function and returns a boolean based on the equality of the self Member and rhand Member's lowered strings (Membe r ("bass"Sue"Member ("Bass", "sue") should return Each Band object will contain the following information: I. Name of the band (for example, "The Ramones") 2. List containing Member objects that make up the band The Band class will also contain the following methods (other than init. ): 1. def getBandName (self): 2. def getPlayers (self): 3. def getInstruments (self): a. This method will return the name of the band a. This method will return a list of all the players' names This method will return a dictionary containing the types of instruments as its keys and the number of them in the band as its values a. 4. def addMember(self, member): a. This method will append a new member to the band's member list 5. def removeMember (self, member) This method will remove all occurrences (not case sensitive) of the input member in the band's current member list (hint take advantage of the overridden eq method in Member!) a. 6. def str self) a This method will return a string including the name of the band and all of its members along with their instruments. See below for an example. 7. def findPlayer (self, player): a. This method will print each Member's string that has the given input player. If there are multiple Members that share a name, then they should all be printed (maintaining the capitalization of the stored names and instruments). If there are no matching players in the Band's Member objects, then print the name of the band and a note saying there are no players with the given name. See below for an example. 8. def findInst rument (self, instrument) a. This method will print each Member's string that has the given input instrument type. If there are no matching instruments in the Band's Member objects, then print the name of the band and a note saying it doesn't contain the given instrument type. See below for an example

Explanation / Answer

class Memeber:
   def __init__(self,instrument,name):
      self.name = name
      self.instrument = instrument

   def getPlayer(self):
      return self.name

   def getInstrument(self):
      return self.instrument

   def setInstrument(self, instrument):
       self.instrument = instrument

   def setPlayer(self, name):
       self.name = name

   def __str__(self):
       return self.instrument + " player " + self.name

   def __eq__(self, rhand):
       return self.name.lower() == rhand.getName().lower()


class Band:
   def __init__(self, name, l):
       self.name = name
       self.list = l

   def getBandName(self):
       return self.name
      
   def getPlayers(self):
       list1 = []
       for i in range(len(self.list)):
           list1.append(self.list[i].getName())
       return list1

   def getInstruments(self):
       dict = {}
       for i in range(len(self.list)):
           count = 0
           for j in range(len(self.list)):
               if self.list[i].getInstrument() == self.list[j].getInstrument():
                  count = count + 1
           dict[self.list[i].getInstrument()] = count
       return dict

   def addMember(self, p1):
       self.list.append(p1)


   def removeMember(self, p1):
       for i in range(len(self.list)):
           if self.list[i] == p1:
              del self.list[i]
              break

   def __str__(self):
       str1 = self.name + " "
       for i in range(len(self.list)):
           str1 = str1 + str(self.list[i]) + " "
       return str1

   def findPlayer(self,p1):
       found = 0
       for i in range(len(self.list)):
           if self.list[i] == p1:
              found = 1
              print(self.list[i])
       if found == 0:
          print(self.name)
          print("There are no players with given name")

   def findInstrument(self,p1):
       found = 0
       for i in range(len(self.list)):
           if self.list[i].getInstrument() == p1:
              found = 1
              print(self.list[i])
       if found == 0:
          print(self.name)
          print("It does not contain the " + p1)