Python Forum
I am attempting to make a car booking system for my assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am attempting to make a car booking system for my assignment
#1
The code needs to be all in main.py 2. No global variables are allowed 3. No arrays are allowed, use lists instead 4. Must follow the menu stated in the doc 5. Cant use classes, we didnt learn it, this is a beginner class for python 6. SQL or django or others are not allowed to be used. Ive done half of the code, however i need unique id for customer and cars, but im stuck for certain functions because im not sure how to do those. Theres 3 users, admin, unregistered customer and registered customer. Im also using text files to keep all my data. Specific time duration in my assignment doc means the date. If doing all of this is too hard, i hope someone can help me with just the book_cars function at least or one of the functions that i am unsure how to do in admin or registered customer menu ;; -;; For Admin's menu, ive done 1, 2 and 3.a For Unregistered customer's menu, ive done all that needs to be done in the menu For registered customer's menu, ive done only 2 and 5. For admin's menu: 3. b display ALL records of customer payment can be: - Ely's record payment: $200 for 3 days rented 4. a Search specific record of car booking can be:- Select Car id: 1 Car id 1 is booked for customer user Ely. 4. b Search customer payment can be: - Select Customer id: 1 Customer id 1, Ely has payed $200 for car id 1 for 3 days rented 5. Return a Rented car Car id: 1 Customer id 1, Ely has returned rented car id 1 For registered customer's menu: 1. Personal rental history can be: - ****** Ely's rental history ****** 1. Car ID: 1, Type: SUV, Brand: Honda, Color: Red, Year: 2013 3. Booking cars can be:- (Displaying all available cars) Select Car for booking: 1 Please input start date (Year-Month-Date): 2021-02-01 Please input end date (Year-Month-Date): 2021-02-04 Car has successfully been booked, the payment will be $200. 4. Payment and Confirmation of Booking can be: - Car ID: 1, Type: SUV, Brand: Honda, Color: Red, Year: 2013 Selected car has been booked, please pay to confirm booking: $200
Display Cars_Data - Notepad File Edit Format View Help SUV: Honda: Red: 2013 Sedan:Nissan:Black: 2011 Sports: Lamborghini:Yellow: 2015 Minivan: Toyota:Silver: 2009 Electric:Tesla:Black: 2014 Admin_Data - Notepad File Edit Format View Help bob: 123 dave:ch123 sarah:4321 User_Data - Notepad File Edit Format View Help Jely: 123
ONLINE CAR RENTAL SYSTEM (OCRS) SUPER CAR RENTAL SERVICES (SCRS) is one of the fast-growing Online Car Rental Service in Malaysia which help customer to save their time by booking rental cars online from their place. SCRS decided to enhance their online Car Rental booking services by allowing customers to book cars for rent, online. SCRS requires you to develop Python program for the OCRS which have 3 type of users and should contains features stated below: Functionalities of Admin i. ii. 111. iv. Login to Access System. Add Car with details, to be rented out. Modify Car Details Display All records of a. Cars available for Rent b. Customer Payment for a specific time duration Search Specific record of a. Specific Car Booking b. Specific Customer Payment Return a Rented Car. Exit vi. vii. Functionalities of All Customers (Registered / Not-Registered) i. View all cars available for rent. ii. New customer Register to Access other Details 111. Exit Functionalities of Registered Customer i. ii. 111 iv. Login to Access System View Personal Rental History. View Detail of Cars to be Rented Out. Select and Book a car for a specific duration. Do payment to confirm Booking. Exit V. vi.
i. You are required to carry out extra research for your system and document any logical assumptions you made after the research. ii. Your program should use symbolic constants where appropriate. Validations need to be included to ensure the accuracy of the system. State any assumptions that you make under each function. 111. You are required to store all data in text files. There is no limit on the number of text files that can be used but they should be kept minimum. iv. You are expected to use list and functions in your program. Your program must embrace modular programming technique and should be menu-driven. You may include any extra features which you may feel relevant and that add value to the system vi. There should be no need for graphics in your program, as what is being assessed, is your programming skill not the interface design. The marking scheme for the assignment has been provided so that you clearly know how the assessment for this assignment would be done. vii. You should include the good programming practice such as comments, variable naming conventions and indentation. viii. In a situation where a student: - Failed to attempt the assignment demonstration, overall marks awarded for the assignment will be adjusted to 50% of the overall existing marks. - Found to be involved plagiarism, the offence and will be dealt in accordance to APU regulations on plagiarism. ix. You are required to use Python programming language to implement the solution. Use of any other language like C/C++/Java is not allowed.


main.py:-

import datetime


def main():
    time = datetime.datetime.now()
    print("""     
                   _______
                  //  ||\ \\
            _____//___||_\ \___
            )  _          _    \\
            |_/ \________/ \___|
           ___\_/________\_/______
       """)

    print("\n\tWELCOME TO CAR RENTAL SHOP!\n")
    print(f"\tCurrent date and time: {time}")

    while True:
        print("""
        ******** Car Rental Shop ********
        1. Admin
        2. Unregistered Customer
        3. Registered Customer
        4. Exit the program
        """)

        try:
            choice = int(input("Enter your choice: "))
        except ValueError:
            print("Please enter a number!")
            continue

        if choice == 1:
            admin()

        elif choice == 2:
            unregistered_function()

        elif choice == 3:
            registered_function()

        elif choice == 4:
            break

        else:
            print("Please enter a choice between 1-4 only!")


def login(user, password, elevated):
    with open("User_Data.txt" if not elevated else "Admin_Data.txt", "r") as text:
        print("%s Login ********" % ("******** Admin" if elevated else "******** User"))
        for record in text:
            recordList = record.rstrip().split(":")
            if user.lower() in recordList[0].lower() and password in recordList[1]:
                print("Welcome, %s" % user)
                return True
        print("Error! Wrong username or password")
        return False


def admin():
    nValue = input("Enter username: ")
    pValue = input("Enter password: ")
    if login(nValue, pValue, True):
        admin_function()


def admin_function():
    while True:
        print("""
            ******** Access System ********
            1. Add Car with details, to be rented out
            2. Modify Car Details
            3. Display All records of
                a. Cars available for Rent
                b. Customer Payment for a specific time duration
            4. Search Specific record of
                a. Specific Car Booking
                b. Specific Customer Payment
            5. Return a Rented car
            6. Exit to main menu
            """)

        try:
            choice = int(input("Enter a number: "))
        except ValueError:
            print("Please enter a number!")
            continue

        if choice == 1:
            add_cars()

        elif choice == 2:
            modify_cars()

        elif choice == 3:
            option = input("option a or b? ")
            if option == 'a':
                display_cars()
            else:
                print("Customers Payment for a specific time duration")  # customers_payment function goes here

        elif choice == 4:
            option = input("option a or b?")
            if option == 'a':
                print("Specific Search of Car Booking")  # search_car_booking of function goes here
            else:
                print("Specific Search of Customer Payment")  # search_customer_pay function goes here

        elif choice == 5:
            print("return_cars()")

        elif choice == 6:
            break

        else:
            print("Please enter a number between 1-6 only!")


def get_new_users():
    with open("User_Data.txt", "a") as text:
        while True:
            name = input("Enter name to register: ")
            password = input("Enter password: ")
            record = name + ":" + password
            text.write(record + "\n")
            break


def existing_users():
    nValue = input("Username: ")
    pValue = input("Password: ")
    return login(nValue, pValue, False)


def display_cars():
    with open("DisplayCars_Data.txt", "r") as text:
        lines = text.readlines()
        index = 1
        for line in lines:
            splitted = line.rstrip().split(":")
            car_type = splitted[0]
            brand = splitted[1]
            color = splitted[2]
            year = splitted[3]
            print("%d. Type: %s Brand: %s Color: %s Year: %s" % (index, car_type, brand, color, year))
            index += 1


def add_cars():
    with open("DisplayCars_Data.txt", "a") as text:
        car_type = input("Type: ")
        brand = input("Brand: ")
        color = input("Color: ")
        year = input("Year: ")
        text.write("\n%s:%s:%s:%s" % (car_type, brand, color, year))


def modify_cars():
    display_cars()
    with open("DisplayCars_Data.txt", "r") as text:
        index_to_modify = int(input("Select record to modify: "))
        lines = text.readlines()
        if index_to_modify - 1 >= len(lines) or index_to_modify < 0:
            print("Invalid index")
            return
        entries = []
        index = 0
        for line in lines:
            entries.append(line.rstrip().split(":"))
    with open("DisplayCars_Data.txt", "w") as text:
        car_type = input("Type: ")
        brand = input("Brand: ")
        color = input("Color: ")
        year = input("Year: ")
        entries[index_to_modify - 1] = (car_type, brand, color, year)
        for entry in entries:
            text.write("%s:%s:%s:%s\n" % (entry[0], entry[1], entry[2], entry[3]))


def unregistered_function():
    while True:
        print("""
        ******** All Customers ********
        1. View all cars available for rent
        2. Register to SCRS 
        3. Exit to main menu
        """)
        try:
            choice = int(input("Enter a number: "))
        except ValueError:
            print("Please enter a number!")
            continue

        if choice == 1:
            display_cars()

        elif choice == 2:
            get_new_users()
            break

        elif choice == 3:
            break

        else:
            print("Please enter a choice between 1-2 only!")


def registered_function():
    if existing_users() is True:
        while True:
            print("""
            ******** Registered Customer ********
            1. Personal Rental History
            2. Available Cars
            3. Booking Cars 
            4. Payment and Confirmation of Booking
            5. Exit to main menu
            """)
            try:
                choice = int(input("Enter your choice: "))
            except ValueError:
                print("Please enter a number!")
                continue

            if choice == 1:
                print("personal history")  # personal_rental_history function goes here

            elif choice == 2:
                display_cars()

            elif choice == 3:
                book_cars()

            elif choice == 4:
                print("payment and confirmation")  # payment function goes here

            elif choice == 5:
                break

            else:
                print("Please enter a choice between 1-5 only!")
    else:
        print("1. Please re-enter login details")
        print("2. Exit to main menu")
        choice = int(input("Enter choice: "))
        if choice == 1:
            existing_users()
        else:
            return


# this function does not work
def book_cars():
    book_list = []
    with open("DisplayCars_Data.txt", "r") as text:
        lines = text.readlines()
        print(lines)
        select = int(input("Select Car for booking: "))

        for record in lines:
            rec = record.split(":")
            if select in rec[0]:
                counter = 0
                print("1.Type: ", rec[1])
                print("2.Brand: ", rec[2])
                print("3.Color: ", rec[3])
                print("4.Year: ", rec[4])

        if select >= len(lines) or select < 0:
            print("Error")
        list = []


if __name__ == "__main__":
    main()
Reply
#2
Please format text so that it can be read easier.
This hurts my eyes.
jamesaarr likes this post
Reply
#3
(Aug-05-2021, 09:16 PM)Larz60+ Wrote: Please format text so that it can be read easier.
This hurts my eyes.

I think we can skip this part, the text is copy paste of assignment instructions.

We may be able to help much better if OP shares exactly what the code is doing wrong and what the expected result is.
jamesaarr likes this post
Reply
#4
Hello,

The way you've formatted your question is awful. Please try to be concise in future. From what I understand you are looking at ways to store historic payments for specific customers and a way to generate unique customer ID's? I would recommend you look at the Import csv library as a way to store this information, and I would in turn recommend you look at the sha256 library as a way to encrypt the user details. This way you can save the payment details to your external csv, add to it and update it through your program, and using the pandas library you could view it nicely in your program as a table etc. For example:

import csv
import pandas as pd

list_of_data = []
with open('users.csv',newline="") as users:
    user_read = csv.DictReader(users)
    for row in user_read:
        list_of_data.append(row['Data'])
Save each row to a seperate list then you can put it into a complete dictionary.

Then you can use pandas to display the data in the console, if you install pandas, try the code below to get a rough idea:
import pandas as pd

df1 = pd.DataFrame({
    'id' : [1,2,3,4],
    'Name' : ["Jim","Bob","Harry","Ken"]})
print(df1)
EDIT:

You can easily save a list to a dictionary with the below, the pandas code will also display it nicely.

import pandas as pd
a = [1,2,3,4]
data = {
    'id': a,
    'Name' : ["Steve","Kevin","Ken","Ella"]}

df1 = pd.DataFrame(data)
print(df1)
Output:
id Name 0 1 Steve 1 2 Kevin 2 3 Ken 3 4 Ella
while dad_has_cigs == True:
    happiness = True
    if dad_has_cigs == False:
    print("Dad come home!")
    happiness = not happiness
    break
Reply
#5
It took me about 20 minutes, but I still didn't understand what the deal was. If the question is how to save your payment history, the answer is above. If the problem is something else, then I don't know what you need. The program itself seems to work, if you need the text part, this is the wrong forum. There are services like <url snipped> or even separate forums dedicated to training and reporting. Good luck with your project and I think it will work out.
Gribouillis write Aug-01-2023, 01:04 PM:
Promotion link removed. Please read the rules of the forum.
Reply
#6
Refer here for more information: https://www.zealousys.com/blog/vehicle-booking-system/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Assignment to make a multiple choice game blacklight 1 2,118 Aug-14-2020, 02:37 AM
Last Post: Larz60+
  Unbound local error while attempting to reference a list molassascookieman 1 2,122 Mar-26-2019, 08:48 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020