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
  • PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a...

    PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a few instance attribute and a few instance methods to support those attributes. In the next assignment, the TripleString class will help us create a more involved application. Before we do that though, we have to thoroughly test our TripleString implementation. Specifications The class TripleString will contain symbolic constants, instance attributes, and instance methods. ▶ Class symbolic constants This class has 3 symbolic constants, which...

  • 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...

  • Code Example 14-2 class Die: def __init__(self): self.__value = 1 def getValue(self): return self.__value    def...

    Code Example 14-2 class Die: def __init__(self): self.__value = 1 def getValue(self): return self.__value    def roll(self): self.__value = random.randrange(1, 7) Refer to Code Example 14-2: Given a Die object named die, which of the following will print the value of the __value attribute to the console?    a.   print(die.getValue())    b.   print(die.roll())    c.   print(die.value)    d.   print(die.__value) To prevent another programmer from directly accessing the attributes of an object, you use    a.   instantiation    b.   composition   ...

  • ***IN PYTHON 2.7****Augment the following code with a new class named 'Coin'. Coin should inherit from...

    ***IN PYTHON 2.7****Augment the following code with a new class named 'Coin'. Coin should inherit from Die, with the following modifications; The constructor should not take any arguments; a coin always has two sides add a flip() method that uses the roll() method from the parent class. If roll returns 1; flip should return "HEADS". If roll returns a 2, flip should return "TAILS" Do not override the roll or rollMultiple methods from the parent class #!/usr/bin/python # your class...

  • 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...

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