Question
URGENT!

Consider the following code for the definition of a Home object: 1 This class also contains getters, setters and a _str_metho
0 0
Add a comment Improve this question Transcribed image text
Answer #1

We can create a derived class Apartment, by specifying the name of base class, Home, along with the name of derived class.

  1. Create a derived class Apartment
  2. Define a constructor method
  3. Call the constructor method of class, Home, and pass owner and address.
  4. Set the rental price
  5. Define getter and setter methods for rental_price.
  6. Define __str__() function for Apartment class.
  7. Create object of Apartment class.
  8. Print owner, address and rental_price

Program:

Note: Please double-check the indentation using the screenshot provided as reference.



class Home:
        def __init__(self, owner, address):
                self.__owner = owner
                self.__address = address
        def get_owner(self):
                return self.__owner
        def set_owner(self, owner):
                self.__owner = owner
        def get_address(self):
                return self.__address
        def set_address(self, address):
                self.__address = address
        def __str__(self):
                return "[ Owner : " + self.__owner + ", Address : " + self.__address + " ]"

class Apartment(Home):                                          # class Apartment inherits from class Home
        def __init__(self, owner, address, rental_price): # constructor method
                super().__init__(owner, address)        # call constructor of Home class
                self.__rental_price = rental_price      # set rental_price
        def get_rental_price(self):                     # getter method for rental_price
                return self.__rental_price                      # returns rental_price
        def set_rental_price(self, rental_price): # setter method for rental price
                self.__rental_price = rental_price      # sets rental_price
        def __str__(self):                                              # __str__() methods
                # returns a string representation of Apartment
                return "[ Owner : " + self.get_owner() + ", Address : " + self.get_address() + ", Rental Price : " +self.__rental_price + " ]"

apt1 = Apartment("abc", "address1", "1234")             # create an object of Apartment
print("Owner : ", apt1.get_owner())                             # print owner name
print("Address : ", apt1.get_address())                         # print address
print("Rental Price : ", apt1.get_rental_price())       # print rental price
print("Apartment : ", apt1)                                             # print apartment object, by default it calls __str__()

Screenshot:

class Home: def __init_(self, owner, address): self owner = owner self._address = address def get_owner(self): return self. _

Output:

Owner : abc Address : address1 Rental Price : 1234 Apartment : [ Owner : abc, Address : addressi, Rental Price : 1234 ]

Please don't forget to give a Thumbs Up.

Add a comment
Know the answer?
Add Answer to:
URGENT! Consider the following code for the definition of a Home object: 1 This class also...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Urgent! Consider the following code for the point class studied in week 2: Import math class...

    Urgent! Consider the following code for the point class studied in week 2: Import math class Point: #static attribute _count = 0 # to count how many points we have created so far # initialization method def _init__(self, x = 0, y = 0): #default arguments technique self._x = x self._y=y Point_count += 1 #updating the point count #updating the Point count #getters def getX(self): return self._x def getY(self): return self._y def printPoint(self): return " + str(self._x)+ ' ' +...

  • Using the following code: store.py from abc import ABC,abstractmethod class Store(ABC): #creating a abstract class name=''...

    Using the following code: store.py from abc import ABC,abstractmethod class Store(ABC): #creating a abstract class name='' #declaring attributes in class address='' status='' sales_tax_percentage=0.0 def __init__(self,name,address,status,sales_tax_percentage): #init method to initialize the class attributes self.name=name self.address=address self.status=status self.sales_tax_percentage=sales_tax_percentage def get_name(self): #Getter and setter methods for variables return self.name def set_name(self,name): self.name=name def get_address(self): return self.address def set_address(self,address): self.address=address def set_status(self,status): self.status=status def get_status(self): return self.status def set_sales_tax_percentage(self,sales_tax_percentage): self.sales_tax_percentage=sales_tax_percentage def get_sales_tax_percentage(self): return self.sales_tax_percentage def is_store_open(self): #check store status or availability if self.status=="open": #Return...

  • Finish each function python 3 LList.py class node(object): """ A version of the Node class with...

    Finish each function python 3 LList.py class node(object): """ A version of the Node class with public attributes. This makes the use of node objects a bit more convenient for implementing LList class.    Since there are no setters and getters, we use the attributes directly.    This is safe because the node class is defined in this module. No one else will use this version of the class. ''' def __init__(self, data, next=None): """ Create a new node for...

  • Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def...

    Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def __init__(self, make, model, year) Methods in BMW parent class (can leave as method stubs for now): startEngine() -must print "The engine is now on." stopEngine() -must print "The engine is now off." Make another class called ThreeSeries -Must inherit BMW Hint: class ThreeSeries(BMW): -Also passes the three attributes of the parent class and invoke parent Hint: BMW.__init__(self, cruiseControlEnabled, make, model, year) -Constructor must have...

  • In PYTHON 3- Implement a subclass (described below) of "Word Guess", a variant of the game...

    In PYTHON 3- Implement a subclass (described below) of "Word Guess", a variant of the game Hangman. In this game, a word is first randomly chosen. Initially, the letters in the word are displayed represented by "_”.   For example, if the random word is "yellow”, the game initially displays "_ _ _ _ _ _”. Then, each turn, the player guesses a single letter that has yet to be guessed. If the letter is in the secret word, then the...

  • It's my python homework. Not Java. Design type 1: # Creating an object of the class...

    It's my python homework. Not Java. Design type 1: # Creating an object of the class "DeAnzaBurger" theOrder = DeAnzaBurger() # calling the main method theOrder.main() # And the class is like: class DeAnzaBurger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own deign.    .... # That...

  • Task 2: SecretWord class: Download and save a copy of LinkedLists.py (found at the bottom of...

    Task 2: SecretWord class: Download and save a copy of LinkedLists.py (found at the bottom of this assignment page on eClass). In this file, you have been given the complete code for a LinkedList class. Familiarize yourself with this class, noticing that it uses the Node class from Task 1 and is almost identical to the SLinkedList class given in the lectures. However, it also has a complete insert(pos, item) method (which should be similar to the insert method you...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Consider the following class which will be used to represent complex numbers: class Complex: def init__(self,...

    Consider the following class which will be used to represent complex numbers: class Complex: def init__(self, real, imaginary): self. real = real self._imaginary = imaginary def real = self._real + rhsValue. _real imaginary = self._imaginary + rhsValue. _imaginary return Complex(real, imaginary) What code should be placed in the highlighted blank so that class Complex will support the addition operation? O add( real, imaginary) 0 +(self, rhsValue) 0 _____(self, rhsValue) O add( self, real, imaginary) O__add__(self, rhsValue) What can you deduce...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT