self.title = title        self.director = director        self.producer = producer        self.release_date = release_date        self.duration = duration        self.dvd_id = dvd_id

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter3: Using Methods, Classes, And Objects
Section: Chapter Questions
Problem 12RQ
icon
Related questions
Question

class dvd:
 

   def __init__(self, title, director, producer, release_date, duration, dvd_id):

 

       self.title = title

       self.director = director

       self.producer = producer

       self.release_date = release_date

       self.duration = duration

       self.dvd_id = dvd_id

 

   def get_title(self):

 

       return self.title

 

   def get_director(self):

 

       return self.director

 

   def get_producer(self):

 

       return self.producer

 

   def get_release_date(self):

 

       return self.release_date

 

   def get_duration(self):

 

       return self.duration

 

   def get_dvd_id(self):

 

       return self.dvd_id

 

 

class customer:

 

   def __init__(self, name, customer_id):

 

       self.name = name

       self.customer_id = customer_id

 

   def get_name(self):

 

       return self.name

 

   def get_customer_id(self):

 

       return self.customer_id

 

 

class store:

 

   def __init__(self):

 

       self.dvds = []

       self.customers = []

 

   def add_dvd(self, dvd):

 

       self.dvds.append(dvd)

 

   def add_customer(self, customer):

 

       self.customers.append(customer)

 

   def rent_dvd(self, dvd_id, customer_id):

 

       for dvd in self.dvds:

           if dvd.get_dvd_id() == dvd_id:

               for customer in self.customers:

                   if customer.get_customer_id() == customer_id:

                       customer.dvds.append(dvd)

                       self.dvds.remove(dvd)

 

   def return_dvd(self, dvd_id, customer_id):

 

       for customer in self.customers:

           if customer.get_customer_id() == customer_id:

               for dvd in customer.dvds:

                   if dvd.get_dvd_id() == dvd_id:

                       self.dvds.append(dvd)

                       customer.dvds.remove(dvd)

 

   def get_dvd(self, dvd_id):

 

       for dvd in self.dvds:

           if dvd.get_dvd_id() == dvd_id:

               return dvd

 

   def get_customer(self, customer_id):

 

       for customer in self.customers:

           if customer.get_customer_id() == customer_id:

               return customer

 

   def get_dvds(self):

 

       return self.dvds

 

   def get_customers(self):

 

       return self.customers

 

   def get_dvds_for_customer(self, customer_id):

 

       for customer in self.customers:

           if customer.get_customer_id() == customer_id:

               return customer.dvds

 

 

# main

 

store = store()

 

dvd1 = dvd("The Godfather", "Francis Ford Coppola", "Albert S. Ruddy", 1972, 175, 1)

dvd2 = dvd("The Shawshank Redemption", "Frank Darabont", "Niki Marvin", 1994, 142, 2)

dvd3 = dvd("Pulp Fiction", "Quentin Tarantino", "Lawrence Bender", 1994, 154, 3)

 

store.add_dvd(dvd1)

store.add_dvd(dvd2)

store.add_dvd(dvd3)

 

customer1 = customer("John Smith", 1)

customer2 = customer("Mary Johnson", 2)

customer3 = customer("Mike Williams", 3)

 

store.add_customer(customer1)

store.add_customer(customer2)

store.add_customer(customer3)

 

store.rent_dvd(1, 1)

store.rent_dvd(2, 1)

store.rent_dvd(3, 2)

store.rent_dvd(3, 3)

store.return_dvd(2, 1)

 

print(store.get_dvd(1))

print(store.get_dvd(2))

print(store.get_dvd(3))

 

print(store.get_customer(1))

print(store.get_customer(2))

print(store.get_customer(3))

 

print(store.get_dvds())

print(store.get_customers())

print(store.get_dvds_for_customer(1))

print(store.get_dvds_for_customer(2))

print(store.get_dvds_for_customer(3))

 

Attribute Error: 'customer' object has no attribute 'dvds'

Eliminate This Attribute Error.

 

def __init__(self, name, customer_id):
self.name = name
self.dvds = []
self.customer_id = customer_id
Transcribed Image Text:def __init__(self, name, customer_id): self.name = name self.dvds = [] self.customer_id = customer_id
Expert Solution
steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Database connectivity
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage