Write a class Movie. It should have attributes for the following data: The movie’s name. A dictionary initialized with 5 key/value pairs: The keys should be the numbers 1 through 5, and each value should be initialized to 0. The values signify how many reviews the movie has received with that many stars. i.e., If key 1 is paired with the value 3, that means 3 users have given the movie 1 star. An int variable num_reviews, which tracks how many reviews the film has received.  A constructor that accepts the movie’s name as an argument, sets num_reviews to 0, and initializes the dictionary. It should have the following methods: A property setter and getter for the movie’s name. add_review, which can only be passed the values 1 through 5. As an example, if ‘2’ is passed, that means a review of 2 stars is being added: increment the value associated with the key ‘2’ by one. __str__: Print the movie’s name and its reviews, nicely formatted. For example, something like this: My Movie Name 1 Star: 3 2 Stars: 2, etc... get_average: returns the average value for all movie ratings.  In your main function, create two different Movie objects. Give both movies several user ratings, and then print out their average ratings. No need for user input, everything can be hard-coded.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  • Write a class Movie. It should have attributes for the following data:
    • The movie’s name.
    • A dictionary initialized with 5 key/value pairs: The keys should be the numbers 1 through 5, and each value should be initialized to 0. The values signify how many reviews the movie has received with that many stars. i.e., If key 1 is paired with the value 3, that means 3 users have given the movie 1 star.
    • An int variable num_reviews, which tracks how many reviews the film has received. 
    • A constructor that accepts the movie’s name as an argument, sets num_reviews to 0, and initializes the dictionary.
  • It should have the following methods:
    • A property setter and getter for the movie’s name.
    • add_review, which can only be passed the values 1 through 5. As an example, if ‘2’ is passed, that means a review of 2 stars is being added: increment the value associated with the key ‘2’ by one.
    • __str__: Print the movie’s name and its reviews, nicely formatted. For example, something like this:
      • My Movie Name
      • 1 Star: 3
      • 2 Stars: 2, etc...
    • get_average: returns the average value for all movie ratings. 
  • In your main function, create two different Movie objects. Give both movies several user ratings, and then print out their average ratings. No need for user input, everything can be hard-coded.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Dictionary
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education