Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*In Python 3 please - there should be 2 files: media.py and main.py For this assignment you will write a program to simulate a media

*In Python 3 please - there should be 2 files: media.py and main.py

For this assignment you will write a program to simulate a media library. We will work with three types of media: pictures, music, and movies. Your job is to design and implement a class hierarchy consisting of the Media, Picture, Song, and Movie classes, as described below.

Specification for the classes:

All the following classes are to be implemented in a single modulemedia.py.

Media class

TheMediaclass will be the abstract base class to be inherited by ourSong,MovieandPictureclasses. AllMediaobjects should have a name and a rating. The rating is an integer number (think of this as the number ofstarsgiven).

We will leave many design decisions to you, however you should implement at least the following methods:

  • __init__(name, rating): Where name is a string and rating is an integer.
  • getName()Returns the name of theMediaas a string
  • __str__(): Returns a string representation of a genericMediaobject in the format<>: <>, <> stars.
  • getRating(): Returns the rating as an integer.
  • setRating(value): Takes an integer parameter, and changes the rating of the object.

In addition, you should have astatic abstractmethodadd()that takes no parameters.

Movie class

AMovieis a type ofMediathat has a director and running time (given in minutes). This class has aplay()method that will simulate the task of playing a movie (you can do something simple as printing:<> playing now. TheMovieclass should override the__str__method of its parentMediaclass (although it can also use it!).

Make sure you also implement at least the following methods:

  • A constructor. Your constructor should take all the information needed to initialize the parent class, as well as the director as a string and the running time as a number. The order of the arguments should bename, rating, director, running_time.
  • getDirector(): Returns the director as a string
  • setDirector(name): Sets the director using the stringname.
  • getRunningTime(): Returns the running time as a number.
  • setRunningTime(time): Sets the running time using the integertime.
  • play(): Prints<> playing now.
  • __str__(): Returns a string representation of theMovieobject in the format:Movie: <>, <> stars, Directed by: <>, Running time: <> minutes.

In addition you will have to implement theadd()method for this class. This method should be static, should prompt the user to enter the necessary information to create aMovieobject, and returns a new instance ofMovieas follows:

Enter movie name: Enter director: Enter movie duration: Enter rating: Movie added! 

Song class

ASongis a kind ofMediathat has an artist and an album. This class has aplay()method that will simulate the task of playing a song (see description below). TheSongclass should override the__str__method ofMedia.

In addition, you should implement the following methods:

  • A constructor Your constructor should take all the information needed to initialize the parent class, as well as the artist and album. The order of the arguments should bename, rating, artist, album.
  • getArtist(): Returns the artist as a string
  • setArtist(name): Sets the artist name to the stringname.
  • getAlbum(): Returns the album name as a string
  • setAlbum(name): Sets the album name to the stringname.
  • play(): Prints<> by <> playing now.
  • __str__(): Returns a string representation of theSongobject in the form:Song: <>, <> stars, Artist: <>, Album: <>.

Like theMovieclass, this should have a staticadd()method that prompts the user to enter the necessary information to create aSongobject, and returns a new instance ofSong. The format of the prompts is:

Enter song name: Enter artist: Enter album: Enter rating: Song added! 

Picture class

APictureis a kind ofMediathat has a resolution. The resolution of a picture is an integer number that measures the dots per inch (the minimum resolution of any picture should be 200 dpi).

ThePictureclass should implement at least the following methods:

  • A constructor. Your constructor should take all the information needed to initialize the parent class, as well as the dots-per-inch of the picture, as an integer. The order of the arguments should bename, rating, dpi.
  • getResolution(): Returns the dpi as an integer.
  • setResolution(value): Changes the dpi. The parametervalueis an integer.
  • show(): PrintsShowing <>.
  • __str__(): Returns a string representation of thePicturein the form:Picture: <>, <> stars, Resolution: <> dpi.

Like the previous derived classes, this should also have a staticadd()method that prompts the user to enter the necessary information to create aPictureobject, and returns a new instance of that object.

Enter picture name: Enter dpi: Enter rating: Picture added! 

Main Script

Your main script (main.py) will simulate a media library, where you store allMediaobjects in asingle list. To interact with it you should have a menu that allows the user to perform the following actions:

  • Display all items in theMedialibrary, one per line in the format:<>: <>
  • Display only theSongobjects, one per line in the format:<>: <>
  • Display only theMovieobjects, one per line in the format:<>: <>
  • Display only thePictureobjects, one per line in the format:<>: <>
  • Play aSong: Asks the user to enter the name of theSongasEnter name of the song to play:. If theSongis found play it. If not, displayNo such song in the media library
  • Play aMovie: Asks the user to enter the name of theMovieasEnter name of the movie to play:. If theMovieis found play it. If not, displayNo such movie in the media library
  • Display aPicture: Asks the user to enter the name of thePictureasEnter name of the picture to show:. If thePictureis found display it. If not, displayNo such picture in the media library
  • Add aSong. You will then be prompted to enter a song title, an artist, and a rating as outlined in the class description.
  • Add aMovie. You will then be prompted to enter a the movie name, director, running time, and rating, as outlined in the class description.
  • Add aPicture. You will then be prompted to enter a photo name, resolution, and rating, as outlined in the class description.
  • Quit the program.

You will need a loop to show and process the menu until the user chooses to quit/exit the program. This menu looks like:

*** Media Library *** a. Display all Media b. Display only Songs c. Display only Movies d. Display only Pictures e. Play a Song f. Play a Movie g. Show a Picture h. Add a Song i. Add a Movie j. Add a Picture k. Exit the program Enter your choice: 

Once the user quits, print a goodbye message:Good-Bye!

As always use the text output comparison tests to verify that you are outputting content in the desired format.

Notes:

  • The purpose of this problem is to practice creating and deriving classes and operator overloading.
  • Please make sure to submit a well-written program. Good identifier names, useful comments, and spacing will be some of the criteria that will be used when grading this assignment. Make sure you are using attribute mangling.

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

Step: 3

blur-text-image

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions