Task 4 - Making Classes Using OOP
Task 4 - Making Classes Using OOP
We have had our fun with dictionaries, but we must bid them adieu. Now that you know
about a much more robust form of data storage, we will convert all that we have worked
with so far into classes and objects.
Some boilerplate code has been provided for you in various files, so open up the file
explorer to see what you have. You have to read the instructions in the docstrings of the
methods, create the classes, and define the methods.
You have to choose if these should be class or instance variables, and which class they
should be defined in. Make sure that the data type of these variables also match what you
did in Task 1. The only exception is the coordinates, which is now a tuple of floats (latitude,
longitude).
You should define getters and setters for these variables. There are exceptions for these,
namely: prop_id, full_address, prop_type, coordinates and suburb are static fields and
hence do not need setters, only getters. These values for a property cannot change as that
would change the property itself. The rest of the attributes can change (think renovation)
Getters and setters help us implement an important aspect of OOP called Encapsulation. You can read
more about it here.
For example for the variable bedrooms, one of your classes should have the method:
get_bedrooms(self) -> int that returns the number of bedrooms that exist in the property
and also a method set_bedrooms(self, num_bedrooms: int) -> None that sets the value
num_bedrooms to the bedrooms variable in the class.
You will have some methods as abstract methods in the Property class. When overriding the method, if that
particular method should not have an implementation in one of the child classes, make it return None.
Completing this section should pass the tests from 4.1 to 4.20.
Please DO NOT add any additional parameters to ANY of the given functions.
Again, there are exceptions for these getters and setters, namely: amenity code ,
amenity type and amenity coords are static fields and hence do not need setters, only
getters.
Completing this part should pass the tests from 4.21 to 4.22.
two lists:
You do not need to change this file or this function. As long as you have created the four
classes properly (Property, House, Apartment, Amenity) then this function should run
properly and produce some output for you.
Please remember to always use the getter and setter methods to access the class and instance
variables where appropriate. Using the instance variables directly where a getter or a setter should have
been used will result in a loss of marks.
Some code has already been given to you in the file at the end, and if your classes and the main() method
have been successfully set up, it should print out some legible output.
🚫 YOU MUST NOT CHANGE any of the following elements of the skeleton.
● Class names.
● Class method names, parameters, or return types.