0% found this document useful (0 votes)
38 views

Source Code Explanation

This document describes the source code for a car rental management system. It includes functions for admin and customer login, managing the car inventory, customer bookings and payments, and searching records. Diagrams show how while loops, if statements, and file input/output are used. Sample inputs and outputs demonstrate how the code allows adding, modifying, and viewing car and customer details. The conclusion reflects on the learning experience of designing the system.

Uploaded by

Lim Jin Wei
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Source Code Explanation

This document describes the source code for a car rental management system. It includes functions for admin and customer login, managing the car inventory, customer bookings and payments, and searching records. Diagrams show how while loops, if statements, and file input/output are used. Sample inputs and outputs demonstrate how the code allows adding, modifying, and viewing car and customer details. The conclusion reflects on the learning experience of designing the system.

Uploaded by

Lim Jin Wei
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Source code explanation

Master menu
Diagram 1

As you can see in Diagram 1 a list has been made which consist of 3 numbers
[1, 2, 3] and after that a while loop is used for it to be in a constant loop, it also
prints out 3 outputs which are the options available for us to input one of the
presented choices, a try function is then used for data validation to ensure that
the input being presented is an integer and not an alphabet or word and if it
was then it will ask to select a valid option. The IF function is then used to
break out of the loop and to continue to the specific page that is keyed, but if
the numbers are not from the list it will ask to select a valid option.
Admin Login
Diagram 2

For the Admin Login users are required to enter correct credentials in order to
login, a while loop is used so that the user can re-enter their credentials if they
are incorrect, the split function is used to split the username and password and
store them inside a list of 2 strings, the IF function where “if correctusername
== username and correctpassword == password :” is used so that the info in
the list is matched then it will display “Correct credentials”
Menu
Diagram 1,3,4,5 and 6
All the menu has the same functions and uses the same functions and act as
the menu interfaces for the users, it displays the functions and features the
user can access that when entered the correct input will bring them to the
page.

Display records
Diagram 7

Display records is a function that allows the user to view the records of cars
and customers, it will first display the options that the user can select and
access and based on what they want to access the user would have to enter
the correct integer ( 1 to 4) which will then redirect them to the page, so if the
user would want to see the cars that are rented out he would have to input “1”
which will then direct them to “Cars_rented_out()” and if they enter an invalid
option it will ask the user to enter a valid option.
Cars rented out
Diagram 8

Cars rented out is a function that shows all the cars that are currently
unavailable meaning they are being rented out, it will use the split function to
split the availability and then if the availability of the car is “Notavailable” it will
be shown.

Customer Payments
Diagram 8
Customer payments shows the total amount the customer has to pay for their
rental period, firstly the customer would be asked to enter their username
which the information will be kept in the “Customerbookings.txt” file, it will
then split the username, duration and car_plate as these are the 3 data that is
required, next the “cardetails.txt” file is read and will split the Carplates which
will determine which car the customer is booking and also how much it cost
per day, and finally the total price is calculated by the function “total_price =
int(amount) * int(duration) and this will then print to show how much the
customer will need to pay

Returning rented car


Diagram 9

Return rented car is a function that lets the admin update the system and the
availability of a rented car when it is returned, the “cardetails.txt” file would be
open and carplates and availability would be split and the IF statement where
“if availability == “Notavailable”: linenumber = I” is used to determine and
mark which line number has to be modified which in this case would be the
availability.

This function is then used to replace the “Notavailable” to “available” and a


temp file is also created as well in the “new_file_content += new_line + “\n””
then to determine the line that needs to be modified in the txt file we used
“new_line_content = new_file_content.split(“\n”).

This function is used to take out the specific line from the temp file content
and replaces it inside the existing cardetails.txt file with the specified line
number as if “list_of_lines[linenumber] = new_line_content[linenumber] + “\
n”” is not used it will replace all the lines that have their availability as
“Notavailable”
Adding cars
Diagram 10

This function is used so that the admin can add new cars that can be rented out, for this the
cardetails.txt file would have to be appended, the user would then be ask to enter the car
details which would need to consist of the Carplate (Car_Plate), Car name (Car_Name), Car
price (Car_Price) and Car availability (Car_availability) when done it will add those details
into the cardetails.txt.
Modifying car details
Diagram 11

This function is to modify existing car details in the cardetails.txt file, to do this
the file would have to be open and the lines to be read then strip them into
strings, the car details are then separated and presented to the user as choices
(1. Car Plate, 2. Car name, 3. Price per day, 4. Availability) which then the user
would have to select which detail would they like to modify, for example if the
user chose 1 they will be asked to enter the old car plate of the car and then
the new one, the cardetails.txt file would then be open and the function cars =
line.split(“ “) is then used to split on the spaces and store the results in the list
of 2 strings, then if the old car plate that has been entered matches with the
one in the file it will be replaced with the new car plate.

Customer registration
Diagram 12

Customer registration Is used so that unregistered customers can register a


new account with the company, it will need the user to enter their username
and password, using a while loop and if statement as if the user leaves any of
the field empty it tell them that the field cant be blank and allow them to enter
their username or password again, after they have registered and their
account has been created the customerID.txt file would then open and then
append the information given by the customer into the file with .write function

Search specific record


Diagram 13
This function is used to search customer records, the user would have to first
input what they want to search for example if they would like to search
customer’s bookings they would have to enter 1 which will then bring them to
customer bookings page where they would have to input the customers name
for example “Kelv”, it will then open and search for the username “Kelv” in the
Customerbookings.txt file and if it matches it will print out the information of
the customer.

Sample input and output


Admin
When I run the code it will display the welcome message and ask the user to
choose one of the 3 options available.

For example the user enters “1”, it will then ask for the users username and
password and if entered correctly they will be logged in

Afterwards it will redirect the user to the admin main menu page where they
will then have to select one of the six options presented.

For example the user selected the option to add cars to be rented out, which
will then ask the user to input the car details required which will then be added
into the cardetails.txt file.
As you can see a new car has been added into the cardetails.txt file which is
the Skyline.

After the car has been added it will bring the user back to the admin menu
page, from there the user can then continue to use the other functions if they
choose to

Customer
For this example the customer will input number 2 which will then ask if they
have a registered account with the company

For this example if the customer would like to create an account they would
have to input Yes which will then ask them for their new username and
password, once completed it will create the account

As you can see the new registered customer’s account is then added into the
customerID.txt file
If the customer does not want to register an account they will then be
redirected to the unregistered customer menu where they will only be able to
view all available cars for rent.

As you can see if they input number 1 they will be able to see all the cars which
availability is available

Modify car details

If the admin wants to modify car details they would have to input number 2 at
the admin main menu page when completed it will list out all the cars in the
cardetails.txt and then they would be ask to enter the car ID of the car they
would like to modify
For example the admin entered the car ID “BFG6969” afterwards they are
given the choices to modify they would have to input a number.

In this case the admin would like to change the car plate of the car BFG6969,
they would have to input number 1 which will then ask them to enter the old
car plate of the car followed by the new car plate of the car, when completed it
will change the old car plate to the new one in the cardetails.txt file
Conclusion
In conclusion this assignment has helped us to better understand and
implement the skills that we have learnt in our Python classes, we learnt to
also use materials online to help better understand and enhance the quality of
our work as well, there were definitely many obstacles during the duration of
the assignment and made many mistakes and errors in our code but it also
gave us opportunities to try to figure it out and also to think creatively and
critically, in the end this assignment has been a taste of what we can achieve
and make with Python, we are very grateful to our lecturers and friends for
guiding us throughout the way.

You might also like