Familiarise yourself with Object Oriented concepts and Test Driven Development with Python videos by Anna:
Video #7. OOP and Encapsulation
Video #8. Abstraction, inheritance, Abstract classes
Video #9. Aggregation and Composition
Or if you want to learn more, watch the whole playlist!
In this lab, you will be implementing one of the use-cases for the car rental system; map the conceptual class diagram from last lab to Python classes with their corresponding attributes.
This lab must be completed individually and uploaded to GitHub by Sunday, end of Week 05.
There is a starter code available for this lab, which you can import from https://cgi.cse.unsw.edu.au/~cs1531/github/run.cgi/labs.
Here’s a detailed instruction for importing the starter code:
Go to https://cgi.cse.unsw.edu.au/~cs1531/github/run.cgi/labs.
Select lab05 and click Import
Follow the link that is shown in the green banner flashed at the top of the screen to go to the place where the repo has been imported
Click on the Clone or download button.
If the title for the dropdown box is Clone with HTTPS click on the Use SSH link on the right. The box should look like the below
Copy the link in the text box
Open a Terminal and navigate to the folder you want the lab to be in
git clone [link] (Replace [link] with the copied link from above step)
Type ls to ensure the folder has been copied correctly
cd [repo_name] to navigate into the cloned repo
Car should NOT be instantiable__str__ method in the class Car (and its derived classes) to provide an appropriate string representation of each class.Check the example output in Task 3 for more clarification on the expected behaviour .
For this task, you only need to implement the use-case to “book a car”. All other use-cases (search for a car, payment etc.) are not required to be implemented. For this use-case, you can ignore the purchase of insurance.
To book a car, the following sequence of steps needs to be taken:
Accept booking details from the user
Create a car booking for the customer and return an email confirmation to the customer advising of the customer’s name, details of car booked, rental period and total rental fee
__str__() methodThe total rental fee should be computed based on the type of car rented and the number of days. The following business rules are to be applied in the computation.
Check the example output in Task 3 for more clarification on the expected behaviour.
Create some test data to demonstrate your implementation using print statements. Write your tests in a separate file called client.py.
Your test must include booking each type of car (small, medium, large, premium) under various booking conditions, especially the rental period.
Provided below is an example of what your test outputs may look like. Note that you do not have to follow the exact format as below, but you are required to test your implementation more rigorously. Marks will be deducted for inadequate testing.
~~~ Print all customers ~~~
Customer <name: Matt, licence: 1>
Customer <name: Isaac, licence: 2>
Customer <name: Taylor, licence: 3>
~~~ Print all cars ~~~
Small Car <Mazda, Falcon, rego: 1>
Medium Car <Mazda, Falcon, rego: 2>
Large Car <Mazda, Falcon, rego: 3>
Small Car <Mazda, Commodore, rego: 4>
Medium Car <Mazda, Commodore, rego: 5>
Large Car <Mazda, Commodore, rego: 6>
Small Car <Holden, Falcon, rego: 7>
Medium Car <Holden, Falcon, rego: 8>
Large Car <Holden, Falcon, rego: 9>
Small Car <Holden, Commodore, rego: 10>
Medium Car <Holden, Commodore, rego: 11>
Large Car <Holden, Commodore, rego: 12>
Small Car <Ford, Falcon, rego: 13>
Medium Car <Ford, Falcon, rego: 14>
Large Car <Ford, Falcon, rego: 15>
Small Car <Ford, Commodore, rego: 16>
Medium Car <Ford, Commodore, rego: 17>
Large Car <Ford, Commodore, rego: 18>
Premium Car <Tesla, model x, rego: 19>
Premium Car <Tesla, A4, rego: 20>
Premium Car <Tesla, S class, rego: 21>
Premium Car <Audi, model x, rego: 22>
Premium Car <Audi, A4, rego: 23>
Premium Car <Audi, S class, rego: 24>
~~~ Make first booking ~~~
=== Booking Successful! ===
Booking details:
Made by Customer <name: Taylor, licence: 3>
Reserve Medium Car <Mazda, Commodore, rego: 5> for 7 days
Locations: <pickup: Sydney, dropoff: Canberra>
Total fee: $525.00
=== Thank you for using Affordable Rentals ===
~~~ Make second booking ~~~
=== Booking Successful! ===
Booking details:
Made by Customer <name: Isaac, licence: 2>
Reserve Premium Car <Tesla, S class, rego: 21> for 12 days
Locations: <pickup: Earth, dropoff: Moon>
Total fee: $2070.00
=== Thank you for using Affordable Rentals ===
~~~ Print all bookings ~~~
Made by Customer <name: Taylor, licence: 3>
Reserve Medium Car <Mazda, Commodore, rego: 5> for 7 days
Locations: <pickup: Sydney, dropoff: Canberra>
Total fee: $525.00
Made by Customer <name: Isaac, licence: 2>
Reserve Premium Car <Tesla, S class, rego: 21> for 12 days
Locations: <pickup: Earth, dropoff: Moon>
Total fee: $2070.00