CS:5110 Introduction to Informatics Fall 2018

Homework 6

Points: 15

Due Date: November 6, 2018 (must submit before class starts) Goal: To give you experience in working with classes.

Your goal is to define classes for an application where a user may explore a library of items (books, movies, music). The class hierarchy I want you to use is provided in the accompanying file. Stubs are included for each relevant class. You do not have to define any more classes but you may if you like.

Code for the following.

  1. All items in the library have a unique id and a unique title. So, if there 20,000 items in the library then the ids run from 1 to 20,000. All items have a date of origin. For books this is the date of publication, for movies, the date of release and for music the date of recording. For each book and for each movie you want to track the genre (mystery, romance, etc.). You may assume that there is a fixed list of genres. Music entries do not have genres but you do track the key instrument which could be null if there is no instrument. Books have authors and you need to track first name and last name of each author. For movies you want to track a list of actors as well as a movie popularity rating (from 1 to 5). For music you want to track the name of the lead person (e.g., lead singer: Michael Jackson, or lead performer: Yo-Yo Ma). You also need to track the number of songs in a music item. Also, you want to track the cost, i.e., the amount paid by the library to purchase a copy of each item and the number of copies the library owns. Finally I include a person class simply to store the first and last name of the various people who are mentioned as authors, actors etc.

  2. For each class identify at least one additional instance level attribute of your choice. Extend your code to accommodate these attributes. Clearly document these new attributes in the documentation for each class. You don’t have to do this for the Person class.

  3. Create at least three instances of classes: Book, Movie and Music.

  4. Define a @classmethod with which one can return the number of instances of a class. This should be designed with minimal replication making full use of the class hierarchy. Provide this facility for each of the four classes.

  5. Define a function called findMostExpensive outside the four classes specified that returns the most expensive library item, the cost and the number of copies of that item owned.

Please make sure that your code is efficient, that is, you make use of the class hierarchy and do not have redundant attributes and functions.

Submission Instructions:

Extend the python stubs file with your code. Include meaningful comments in your code so that a user of your classes gets appropriate information at the interface.

Submit your file to the ICON Dropbox setup for this homework.



添加客服微信: abby12468