Case study

  • Property >> Houses and apartments
  • Rentals and purchases also seem to require separate representation. Both property types will require a method to display the characteristics of that property. At the moment, no other behaviors are apparent.
  • Rental properties rent per month, whether property is furnished, and whether utilities are included, and if not, what they are estimated to be.
  • Properties for purchase will need to store the purchase price and estimated annual property taxes.
  • For our application, we’ll only need to display this data, so

  • we can get away with just adding a display() method similar to that used in the other classes.
  • Finally, we’ll need an Agent object that holds a list of all properties, displays

  • Agent would need to know a lot of information about the types of properties.
  • Another alternative would be to put the prompts in the initializer or even a constructor for each class, but this would not allow the classes to be applied later in a GUI or web application in the future. A better idea is to create a static method that
    does the prompting and returns a dictionary of the prompted parameters. Then all the Agent has to do is prompt the user for the type of property and payment method, and ask the correct class to instantiate itself.

The Apartment class extends Property, and is similar in structure:

(The display() and __init__() methods call their respective parent class methods using super() to ensure the Property class is properly initialized. )

Let’s explore what this validation function would look like:

Now, let’s update our Apartment.prompt_init method to use this new function for validation:

Now we’re ready to build the House class. This class has a parallel structure to Apartment, but refers to different prompts and variables:

Check output:—
>>> from “filename” import Property
>>> var = HouseRental.prompt_init()
Enter the square feet: 1
Enter number of bedrooms: 2
Enter number of baths: 3
Is the yard fenced? (yes, no) no
Is there a garage? (attached, detached, none) none
How many stories? 4
What is the monthly rent? 5
What are the estimated utilities? 6
Is the property furnished? (yes, no) no

>>> house = HouseRental(**var)
>>> house.display()
square footage: 1
bedrooms: 2
bathrooms: 3
# of stories: 4
garage: none
fenced yard: no
rent: 5
estimated utilities:
6 furnished: no

Check output :—

>>>From “filename” import Agent
>>> agent = Agent()
>>> agent.add_property()
What type of property? (house, apartment) house
What payment type? (purchase, rental) rental
Enter the square feet: 900
Enter number of bedrooms: 2
Enter number of baths: one and a half
Is the yard fenced? (yes, no) yes
Is there a garage? (attached, detached, none) detached
How many stories? 1
What is the monthly rent? 1200
What are the estimated utilities? Included
Is the property furnished? (yes, no) no
>>> agent.add_property()
What type of property? (house, apartment) apartment
What payment type? (purchase, rental) purchase
Enter the square feet: 800
Enter number of bedrooms: 3
Enter number of baths: 2
What laundry facilities does the property have? (coin, ensuite, one) ensuite Does the property have a balcony? (yes, no, solarium) yes
What is the selling price? $200,000
What are the estimated taxes? 1500
>>> agent.display_properties()
square footage: 900
bedrooms: 2
bathrooms: one and a half
# of stories: 1
garage: detached
fenced yard: yes
rent: 1200 estimated
utilities: included
furnished: no
square footage: 800
bedrooms: 3
bathrooms: 2

laundry: ensuite
has balcony: yes
selling price: $200,000
estimated taxes: 1500

Open chat