Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Movie.py classThe Movie . py file will contain the definition of a Movie.We will define the Movie attributes as follows:title - str that represents the

Movie.pyclassTheMovie.pyfile will contain the definition of a Movie.We will define the Movie attributes as follows:title-strthat represents the title of the movie.Your program should ensure this field will be stored as a Python title (usestr.title()method)(yes, you will havetitle.title()in your code :-)).genre-strthat represents the genre of the movie.Your program should ensure that this field will be stored in all upper-case characters.year-intthat represents the release year of a movie.You will write a constructor that allows the user to construct a Movie object by passing in values for all of the fields.Your constructor should set these attributes with the valueNoneby default.__init__(self, title, genre, year)In addition to your constructor, your class definition should also support setter methods that can update the state of the Movie objects:setTitle(self, title)setGenre(self, genre)setYear(self, year)Each Movie object should be able to call a methodtoString()that you will implement, whichreturns astrwith all the movie attributesEXACTLY as shown (i.e., the string should contain all attributes in the following EXACT format"Title"(GENRE)- YEAR):movie1= Movie("About time", "Drama", 2013)print(movie1.toString())print() # separate two movies with a newlinemovie2= Movie("eternal sunshine of the spotless mind", "Sci-Fi",2004)print(movie2.toString())Output:"About Time" (DRAMA)-2013"Eternal Sunshine Of The Spotless Mind" (SCI-FI)-2004IMPORTANT:The.toString()return value in the example above doesnotcontain a newline character (
) at the end.MovieList.pyTheMovieList.pyfile will contain the definition of a single MovieList object.AnMovieListobject will contain a dictionary structure where the keys of the dictionary will be astrtype representing a Movies genre (all upper-case characters).The dictionary value will be a list of Movie objects that the MovieList contains. Note that the order of the Movies in the list is based on when the Movie object was inserted into the dictionary structure (most recent Movie inserted will be at the end of the list).Your code should support the following constructor and methods:__init__(self)- Constructor that initializes the dictionary structure of the MovieList class. Initially, this dictionary should be empty.addMovie(self, movie)- Adds a Movie object (movie) to the MovieList. The inserted Movie object should be added to the end of the list of existing movies that are of the same genre. You may assume that a movie with the same attributes does not already exist in the MovieList when this method is called.removeMovie(self, movie)- Removes a Movie object (movie) from the MovieList if it exists. Your code will need to check that the provided parametermovieobject has the same attributes (title, genre, year) as an existing movie in the MovieList, if it is to be removed from the MovieList.removeGenre(self, genre)- Removes all movies of a certain genre from the MovieList if it exists. Your code will need to remove the genre entry from the MovieLists dictionary. Note: the providedgenreparameter value may be input in either lower / upper case.getMoviesByGenre(self, genre)- Returns a string of all movies of a certain genre. This string should consist of a collection of strings - one line for each movie.Since each movie will be in its own line within a single string, a newline character (
) should be inserted between each line (if applicable) EXCEPT at the very last line where no newline character should exist.The order of the Movies in this string will be dictated by the order of the Movies in the MovieLists list for the Movies genre.The MovietoString()method should be used when constructing this methods return string.If no Movies of the specified genre exist in the MovieList, then this method returns an empty string ("").Note: thegenreparameter value may be in either lower / upper case.doesMovieExist(self, movie)- Returns a BooleanTrueif the parametermovie(with matching title, genre, year) exists in the MovieList. ReturnsFalseotherwise.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Identify global safety and health issues.

Answered: 1 week ago

Question

Discuss health care in the global environment.

Answered: 1 week ago