a python program

Download the lab7.zip file to extract 2 files:lab7.py and lab7input.txt.

The lab7.py file has the main driver for a few classes that you will write: a class that simulates a media player and a hierarchy of media classes to represent the CDs and DVDs that the media player works with.

The program should run without any modification to the main function in lab7.py

Create a new file called media.py that contains the following classes:

Media class

Asuperclass that has:

  • the following attributes: title (a string), play time (a number), and played (a boolean)
  • a constructor that requires a title, optional play time that’s defaulted to 0, optional played that’s defaulted to False (for not played yet)
  • an abstract method __repr__

CD class

A subclass of the Media class that has:

  • the following additional attributes: artist (a string) which is required, tracks (a number) which is optional
  • a constructor that runs the Media class constructor and initialize its own instance variables. The tracks variable is defaulted to 0
  • the following additional attributes: rating (a string) which is optional
  • a constructor that runs the Media class constructor and initialize its own instance variable. The rating variable is defaulted to None

DVD class

A subclass of the Media class that has:

The following methods are needed, it’s up to you to decide in which class to put them:

  • setPlayTime: to set the optional play time attribute
  • setTracks: to set the optional number of tracks
  • setRating: to set the optional rating attribute
  • play: to simulate the DVD or CD being played. This method sets the played attribute to True, and then it loops the number of play time and prints the count from 1 to the play time, with a system pause of 1/2 second in between the count. Here’s the code to use:

print(count, end=’ ‘, flush=True)# print counts all on one line, flushing the input stream every time

time.sleep(0.5)# import timeat the top of the file

See the sample output.

Feel free to add other methods in the Media classes as you see the need.

Create a new file called mediaPlayer.py with the class:

MediaPlayer class

This class works with the Media subclasses and has:

  • The following attributes: a list of Media objects
  • A constructor that
    • reads the media info from the file lab7input.txt. Each line of the file has information for one media:
    • For any line that doesn’t have the correct format (no CD or DVD as first word), use exception handling to print the line and then print “ignoring error” so the user knows, but keep reading the input file.
    • For the lines that have missing information, prompt the user for the missing information. See sample output.
      Your code should be able to work with any missing optional fields on any line of input. Don’t hard code the user prompts for specific fields or lines that are in this particular lab7input.txt.
    • Once you have all information, create the appropriate Media object (CD or DVD) and add it to the list of Media objects.
    • Don’t forget to have exception handling for when the file doesn’t exist. In this case terminate the program.
  • A play() method that:
    • Loops through all the Media objects in the list and:

CD, title, artist, play time, tracks orDVD, title, rating, play time
Some of the lines have missing information and one line is not in the correct format.

– first print all information of the object by using the __repr__ method of the Media object

– then call the play() method of the Media object

See sample output

  • A shuffle() method that:
  • Make sure instance variables are private
  • This means use accessor methods for private variables if you’re not writing methods for the class
  • Not all variables that you use in a method need to be instance variables. Some are simply local variables.

– first call the play() method of the Media object

– then print all information of the object by using the __repr__ method of the Media object

Feel free to add other methods as you see the need.

Additional Considerations

Sample output is on next page.

When done, upload your mediaPlayer.py and media.py files.No need to upload lab7.py.

Sample program output: (user input is in blue)

Missing info on line: CD, OK Computer, Radiohead

Enter length of play time: 3

Missing info on line: CD, OK Computer, Radiohead

Enter number of tracks or 0 for no track info: 12

Missing info on line: DVD, The Godfather

Enter rating or None for no rating: No rating

Missing info on line: DVD, The Godfather

Enter length of play time: 6

Error in line: error line

### ignoring error

Missing info on line: DVD, The Shawshank Redemption, R

Enter length of play time: 3

Playing all of collection

Playing:The Dark Side of the Moon byPink Floyd, 15 tracks, play time: 5

1 2 3 4 5## note that all these counts should be printed out with a half second pause

Playing:OK Computer byRadiohead, 12 tracks, play time: 3

1 2 3

Playing:The Godfather, rating: No rating, play time: 6

1 2 3 4 5 6

Playing:The Shawshank Redemption, rating:R, play time: 3

1 2 3

Playing:Abbey Road byThe Beatles, 12 tracks, play time: 4

1 2 3 4

Playing:Revolver byThe Beatles, 14 tracks, play time: 5

1 2 3 4 5

Playing:Schindler’s List, rating:R, play time: 5

1 2 3 4 5

Play in shuffle mode

1 2 3 4 5

Played:Revolver byThe Beatles, 14 tracks, play time: 5

1 2 3 4

Played:Abbey Road byThe Beatles, 12 tracks, play time: 4

1 2 3 4 5

Played:Schindler’s List, rating:R, play time: 5

1 2 3

Played:OK Computer byRadiohead, 12 tracks, play time: 3

1 2 3 4 5 6

Played:The Godfather, rating: No rating, play time: 6

1 2 3 4 5

Played:The Dark Side of the Moon byPink Floyd, 15 tracks, play time: 5

1 2 3

Played:The Shawshank Redemption, rating:R, play time: 3

 
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.