Create two files; “a module that defines Four classes” and “a program that execu
ID: 3666481 • Letter: C
Question
Create two files; “a module that defines Four classes” and “a program that executes and tests the four classes”. The module file defines a Superclass Highville and Three subclasses that you should code.
class Highville:
def __init__(self,floors,area):
self.__floors = floors
self.__area = area
def show_info(self):
print('Floors:',self.__floors,', Room area:',self.__area)
class Apartment:
inherits from Highville and adds a numeric attribute for number of bedrooms.
overrides the show_info() method by:
calling the Highville class show_info() method to display the floors and area attributes.
printing the purpose of an apartment and the number of bedrooms.
class Factory:
inherits from Highville and adds a string attribute for the product manufactured by the factory.
overrides the show_info() method by:
calling the Highville class show_info() method to display the floors and area attributes.
printing the purpose of a factory and the product it makes.
class Retail:
inherits from Highville and adds a string attribute for the usage of the retail building.
overrides the show_info() method by:
calling the Highville class show_info() method to display the floors and area attributes.
printing the purpose of the retail building and the usage.
In the executable file's main function:
create an Apartment instance and execute its show_info() method.
create a Factory instance that makes cell phones and execute its show_info() method.
create a Retail instance to represent a clothing shop and execute its show_info() method.
create another Commercial instance to represent a shopping mall and execute its show_info() method.
SAMPLE OUTPUT
Apartment
Floors: 2 , room area: 3000
For people to live: 5 bedrooms
Factory
Floors: 6 , room area: 300000
For making cell phones
Retail
Floors: 17 , room area: 600000
Retail clothing shop
Commercial
Floors: 4 , room area: 100000
Commercial shopping mall
Explanation / Answer
This below python script have implemented based on the given input conditions and parent child relationship between the classes. see the below python script is working fine..
Code:
class Highville(object):
def __init__(self,floors,area):
self.__floors = floors
self.__area = area
def show_info(self):
print('Floors:',self.__floors,', Room area:',self.__area)
class Apartment(Highville):
def __init__(self,floors,area,rooms):
self.__floors = floors
self.__area = area
self.__room = rooms
def show_info(self):
print('Floors:',self.__floors,', Room area:',self.__area)
print('For people to live:',self.__room,', bedrooms')
class Factory(Highville):
def __init__(self,floors,area,product):
self.__floors = floors
self.__area = area
self.__product = product
def show_info(self):
print('Floors:',self.__floors,', Room area:',self.__area)
print('For making:',self.__product)
class Retail(Highville):
def __init__(self,floors,area,usage):
self.__floors = floors
self.__area = area
self.__usage = usage
def show_info(self):
print('Floors:',self.__floors,', Room area:',self.__area)
print('Retail:',self.__usage)
class Commercial(Highville):
def __init__(self,floors,area,usage):
self.__floors = floors
self.__area = area
self.__usage = usage
def show_info(self):
print('Floors:',self.__floors,', Room area:',self.__area)
print('Commercial:',self.__usage)
if __name__ == "__main__":
sm = Apartment(2,3000,5)
print sm.show_info()
sm2 = Factory(6,300000,'cell phones')
print sm2.show_info()
sm3 = Retail(17,600000,'clothing shop')
print sm3.show_info()
sm4 = Commercial(6,300000,'shopping mall')
print sm4.show_info()
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.