Question

In: Computer Science

QUESTION 13 Implement in Python and test the classes shown in the UML below. The LibraryItem...

QUESTION 13

  1. Implement in Python and test the classes shown in the UML below. The LibraryItem class shown in the UML, represents an item that the library issues to students. The partial Python code is provided and It has the following attributes. Test the program by creating a list of books and a list of DVDs and printing the details of each element in the list.

    Attribute

    Description

    ID

    The ID of the item.

    createdate

    The date the item was created as dd/mm/yyyy

    title

    The title of the item.

    class LibraryItem:
        def __init__(self,ID="",year=0,title=""):
            self.ID=ID
            self.year=year
            self.title=title
    
        def getLoanPeriod(self):
            return 0
    

    A) Implement the Book class. It inherits from LibraryItem. Furthermore, it has this additional attribute

    Attribute

    Description

    author

    The author of the book

    Electronic

    This tells whether the book is available as an electronic book (e book)

    Implement the getLoanPeriod function in this way:

    - If the book was written before the year 2000, the loan period will be 14 days.

    - If the book was written after or in 2000, the loan period will be 7 days.

    B) Implement the DVD class. It inherits from LibraryItem. Furthermore, it has this additional attribute

    Attribute

    Description

    length

    The length of the DVD. Example: “2 hours: 30 minutes”

    HD

    Whether the DVD is available in HD (High Definition) or not

    Implement the getLoanPeriod function in this way:

    - If the DVD is available in HD format, the loan period will be 3 days. Otherwise, the loan period will be 7 days.

Solutions

Expert Solution

Here is the Python code:

import datetime

class LibraryItem:
    def __init__ (self, ID=0, year = 2000, month = 1, day = 1, title = ""):
        self.ID = ID
        self.year = year
        self.createDate = datetime.datetime (year, month, day)
        self.title = title
        
    def getLoanPeriod (self):
        return 0

class Book (LibraryItem):
    def __init__ (self, ID=0, year = 2000, month = 1, day = 1, title = "", Author = "", Electronic = 1):
        self.Author = Author
        self.Electronic = Electronic
        LibraryItem.__init__ (self, ID, year, month, day, title)
        
    def getLoanPeriod (self):
        if self.year < 2000:
            return 14
        else:
            return 7

class DVD (LibraryItem):
    def __init__ (self, ID=0, year = 2000, month = 1, day = 1, title = "", length = "", HD = 1):
        self.length = length
        self.HD = HD
        LibraryItem.__init__ (self, ID, year, month, day, title)
        
    def getLoanPeriod (self):
        if self.HD == 1:
            return 3
        else:
            return 7

l1 = Book (1, 1998, 10, 20, "Book 1", "Auth 1", 1)
l2 = Book (2, 2018, 11, 21, "Book 2", "Auth 2", 0)
l3 = DVD (3, 2018, 12, 22, "DVD 1", "2 hours 30 mins", 1)
l4 = DVD (4, 2017, 3, 4, "DVD 2", "1 hours 25 mins", 0)

print (l1.createDate, l1.getLoanPeriod())
print (l2.Author, l2.getLoanPeriod())
print (l3.HD, l3.getLoanPeriod())
print (l4.length, l4.getLoanPeriod())

Related Solutions

Please create a python module named homework.py and implement the classes and methods outlined below. Below...
Please create a python module named homework.py and implement the classes and methods outlined below. Below you will find an explanation for each class and method you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to represent a group of students in a...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
can you please convert this python code into java? Python code is as shown below: #...
can you please convert this python code into java? Python code is as shown below: # recursive function def row_puzzle_rec(row, pos, visited):    # if the element at the current position is 0 we have reached our goal    if row[pos] == 0:        possible = True    else:        # make a copy of the visited array        visited = visited[:]        # if the element at the current position has been already visited then...
Use the UML tool to draw a UML class diagrambased on the descriptions provided below....
Use the UML tool to draw a UML class diagrambased on the descriptions provided below.The diagram should be drawn with a UML toolIt should include all the classes listed below and use appropriate arrows to identify the class relationshipsEach class should include all the described attributes and operations but nothing elseEach constructor and method should include the described parameters and return types - no more and no lessPlease do one of the following in JavaDescriptions of a PriceBecause of the...
Drag the appropriate classes of matter into the boxes below to answer each question. Classes----- Homegeneous,...
Drag the appropriate classes of matter into the boxes below to answer each question. Classes----- Homegeneous, Heterogeneous, Pure substance . In which of these classes must two or more substances be present? ________________ Which of these classes could not possibly have a variable composition?_______________ For which of these classes is separation into simpler substances by physical means possible?________________
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an infix expression to a postfix expression. The PostFixCalculator class evaluates a postfix expression. This means that the expressions will have already been converted into correct postfix form. Write a main method that prompts the user to enter an expression in the infix form, converts it into postfix, displays the postfix expression as well as it's evaluation. For simplicity, use only these operators, + ,...
Des/ign, implement, (Auto, Home, Life) as classes and test them, that represent different insurance policies.
Des/ign, implement, (Auto, Home, Life) as classes and test them, that represent different insurance policies. A policy contains information used by an insurance company to provide financial assi/stance in the event of an accident. It also contains information used to compute how much money, also called acommission. Develop instance variables, constructors, get/set methods, and a toString method for each class. Create a driver class called PolicyTest, whose main method creates objects from each type of class, sets each object with...
**Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class...
**Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class must be in separate file. Draw an UML diagram with the inheritance relationship of the classes. 1. The Athlete class a. All class variables of the Athlete class must be private. b.is a class with a single constructor: Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender). All arguments of the constructor should be stored as class variables. There should only...
Please answer only Question 12 and 13. Question 12: In reference to the original sequence (shown...
Please answer only Question 12 and 13. Question 12: In reference to the original sequence (shown in Question 8), classify each type of mutation present from Questions 9 to 11. Choose the best option for each. mutation #1    mutation #2    mutation #3 A. base substitution - silent mutation B. insertion - frameshift mutation C. deletion - frameshift mutation D. base substitution - missense mutation E. base substitution - nonsense mutation 3 points    QUESTION 13 Questions 9 to...
Language: Python Implement the Book class as demonstrated below. You should not change the Book methods...
Language: Python Implement the Book class as demonstrated below. You should not change the Book methods and implementation as provided. The docstrings in the template contain descriptions of each method. >>> b=Book ( ' Code' , 'Charles Ptzold' 'Computing' , 2001) >>> b Book ( ' Code' , 'Charles Ptzold' 'Computing' , 2001) >>> str (b) ' Code : Charles Ptzold: Computing: 2001 ' >>> b. getTitle ( ) ' Code ' >>> b. getAuthor() ' Charles Ptzold' >>> b....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT