I was stuck in this question. I have done most of the parts but the last part in which we were supposed to compare it, I was stuck in that part could help me up with this in python.
A class called Actor
is designed to model a movie’s actor. It contains three instance variables: name
(String), dateofBirth
(String), and gender
(char of either 'm' or 'f').
The requirements for this class arre:
- There should be getter and setter function for all instance variables.
- Actor also performs in movies so make a list of the movie for each actor and store the names of the movie in it.
- There should be methods
DisplayActor
which displays all the actor data along with the movies. - For an actor, add
AddMovie
function which adds movie name in the list. - Add one more function named
CompareActor
that compares the two objects of actor class and find if they have worked together in the same movie. - This function will return the list of the same movies.
I have attached my code below.
class Actor:
def __init__(self,name,dateofBirth,gender):
self._name = name
self._dateofBirth = dateofBirth
self._gender = gender
self._movies = []
def set_name(self,name):
self._name = name
def set_dateofBirth(self,dateofBirth):
self._dateofBirth= dateofBirth
def set_gender(self,gender):
self._gender = gender
def get_name(self):
return self._name
def get_dateofBirth(self):
return self._dateofBirth
def get_gender(self):
return self._gender
def addmovies(self,movies):
self._movies.append(movies)
def DisplayActor(self):
print("Name of Actor=",str(self._name),"DOB=",str(self._dateofBirth),"Gender=",str(self._gender),"Movies=",str(self._movies))
def main():
act1 = Actor("Fallon","22 january","m")
act1.addmovies("Deadpool")
act1.addmovies("Avengers")
act1.addmovies("Hell Boy")
act1.DisplayActor()
act2 = Actor("John","3 January","m")
act2.addmovies("Hell boy")
act2.addmovies("The Bons Collections")
act2.addmovies("Nemo")
act2.DisplayActor()
main()