Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Assignment
Reminder
This assignment involves a lot of console input/output. You are reminded that the VPL system on HKU Moodle evaluates your program with a full score under the condition that your program output is the EXACT MATCH of the expected output. In other words, any additional or missing space character, newline character, etc., will be treated as errors during the evaluation of your program. Also, you are suggested to design more test cases on your own for testing your program.
You are allowed to use any Python built-in functions. However, you cannot import modules other than those mentioned in this assignment.
Objective
Your client, XYZ Company, provides car rental services. For this assignment, you are to develop a rental system for the company’s internal management of rental transactions. The system should allow managers to analyze rental data and query whether a specific car is available for a new rental.
The techniques we learned in the previous chapters, such as Files, Sets, Dictionaries, and Tuples, would be useful for handling this assignment.
Import Data from File
The company’s rental transaction data is stored in a text (.txt) file. Each row represents a rental transaction with the following fields separated by a single space:
• Car ID (e.g., 01)
• Rental Start Date (e.g., 2024-04-15)
• Customer ID (e.g., 001)
• Rental Fee per Day (integer)
• Rental Days (e.g., 5)
For example, a text file (data.txt) with five records has the following content:
01 2024-04-15 001 50 1
08 2024-04-25 002 45 6
01 2024-05-05 001 50 10
01 2024-05-20 003 60 30
15 2024-05-20 002 45 8
The program should be able to read the file by specifying the name of the data file.
Below is the input and output for loading the file data when the program starts (Text in bold is user input):
Transaction records to import:
data.txt
Imported 5 transaction(s) to the system. Notes:
• The program should automatically assign transaction IDs for each line of the transaction data (the data.txt file). The transaction ID starts with 1 and then increases by 1 for each row of the records. For example, the assigned ID of the first line of the transaction data (01 2024-04-15 001 50 1) is 1, then the next line transaction’s ID is 2, and so on and so forth.
• The program has not been terminated yet. Hints:
• You might use a dictionary to store the transaction records after reading the .txt file.
• You might use split() to split a string into a list.
Main Menu
After importing course sessions from the file, the system enters the main menu and reads a user command repeatedly until the user inputs “Exit” . You should implement the following SIX commands for the system.
The example data.txt file mentioned in the previous section is used for the following cases.
1. Exit
By inputting the command Exit, the program prints "Thank you for using the Car Rental System. Goodbye!" and terminates.
Transaction records to import:
data.txt
Imported 5 transaction(s) to the system.
Exit
Thank you for using the Car Rental System. Goodbye!
2. CarTransaction
By inputting the command CarTransaction, the system lists all cars in the rental transaction records based on the imported data. Prints the car ID and the number of rental transactions for each car. Sorts the records in ascending order by the Car ID.
Transaction records to import:
data.txt
Imported 5 transaction(s) to the system.
CarTransaction
Here is the rental transaction for the cars:
The Car 01 has been rented 3 time(s).
The Car 08 has been rented 1 time(s).
The Car 15 has been rented 1 time(s).
3. CarHistory |
This command can list the transaction summary of the specific Car ID in the format shown in the example below. The records should be sorted by the total number of rental days in descending order. You can assume that no records have the same total number of rental days.
Total number of rental days is the sum of the rental days made by the on .
The records by the same customer should be merged. For example, assuming Customer 001 made two transactions on Car 01 with rental days of 1 and 10 days, respectively, the total number of rental days for Customer 001 on Car 01 should be 11.
Transaction records to import:
data.txt
Imported 5 transaction(s) to the system.
CarHistory | 01
Here is the rental summary for the Car 01:
Customer 003 30 day (s)
Customer 001 11 day (s)
4. RentalPeriodAnalysis | |
This command lists all rental transactions’ starting date time within a specific period (includes the inputted start and end dates). Display the following information for that period (sort the records in ascending order by the transaction ID):
Transaction records to import:
data.txt
Imported 5 transaction(s) to the system.
RentalPeriodAnalysis | 2024-04-15 | 2024-04-25
Rental summary record(s) from April 15, 2024 to April 25, 2024:
01 2024-04-15 001 50 1
08 2024-04-25 002 45 6
5. TopSpendCustomers |
This command determines the top customers based on their total spend amount across all rental transactions. The parameter specifies the maximum number of top
customers to display.
Display the customer ID, total spend amount, and the number of transactions for each top customer. Sort the records in descending order by total spend amount. You can assume that no records have the same total spend amount in the data.
Transaction records to import:
data.txt
Imported 5 transaction(s) to the system.
TopSpendCustomers | 2
Here are the top 2 customer(s) by total spend amount: Customer 003 has spent $1800 on 1 transaction(s).
Customer 002 has spent $630 on 2 transaction(s).
6. CheckCarAvailability | | |
This command allows the manager to check if a specific car is available or occupied during a given rental period. If the car was occupied for any part of the date range, even just a single day, then the entire period is considered occupied. The parameter represents the car's ID to check. The parameter represents the rental start date to check for availability. The parameter represents the number of days lasting for rental.
If the car is not found in the rental transaction records, display the message “The car is not found.” indicating that the car is not in the previous transaction records.
If the car is found, check whether it is available or occupied based on the rental transaction records and the attempted rental period.
Print the message “The Car is available in this period.” indicates the car is available.
If the car is occupied, print the message “The Car is occupied in this period.” Then, print all the occupied days by line (see the example below).