Write Application Python 37 Keeps Track Traffic Fines Violations Noted Traffic Policeman F Q43803401
Write an application in Python 3.7 that keeps track oftraffic fines.
All violations are noted by a traffic policeman in a file as arecord <license number of driver, fine amount>. At the end ofeach day, files from all traffic policemen are collated. If adriver had been charged with more than three violations so far,then he has to be booked for further legal action. Also, the policedepartment provides additional bonus to those policemen who havebrought in large fine earnings. All policemen who have collectedequal to or more than 90% of the highest total fine collected by anindividual policeman, shall be awarded the bonus.
The program should help the police department answer the belowqueries:
1. Find out the drivers who are booked for legal action: All suchlicense numbers are to be output in a file called“violators.txt”.
2. Find out the policemen who are eligible for bonus: The list ofpolicemen eligible for bonus must be output in a file called“bonus.txt”. Additionally,
3. Perform an analysis of questions 1 and 2 and give the runningtime in terms of input size, n.
Use hash tables for keeping track of drivers (and theirviolations), and a binary tree for keeping track of policemen (andtheir bookings).
Data structures to be used:
DriverHash: A separately chained hashtable indexed by license numbers where each entry is of the form< license number, number of violations>. A simple hashfunction h(x) = x mod M, where M is the size of hash table can beused for this.
PoliceTree: This is a Binary Tree ofentries of the form <police ID, total fineamount>
The basic structure of the Police Node will be:
class PoliceNode:
def __init__(self, policeId, fineAmt):
self.policeId = PoliceId
self.fineAmt = fineAmt
self.left = null
self.right = null
Functions:
1. def initializeHash (self): Thisfunction creates an empty hash table that points to null.
2. def insertHash (driverhash, lic): Thisfunction inserts the licence number lic to the hash table. If adriver’s license number is already present, only the number ofviolations need to be updated else a new entry has to becreated.
3. def printViolators (driverhash): Thisfunction prints the serious violators by looking through all hashtable entries and printing the license numbers of the drivers whohave more than 3 violations onto the file violators.txt. The outputshould be in the format
————–Violators————-
<license no>, no of violations
4. def destroyHash (driverhash): Thisfunction destroys all the entries inside the hash table. This is aclean-up code.
5. def insertByPoliceId (policeRoot, policeId,amount): This function inserts an entry <policeId,amount> into the police tree ordered by police id. If the Policeid is already found in the tree, then this function adds up to theexisting amount to get the total amount collected by him. Thisfunction
returns the updated tree.
6. def reorderByFineAmount (policeRoot):This function reorders the Binary Tree on the basis of total fineamount, instead of police id. This function removes the nodes fromthe original PoliceTree, and puts it in a new tree ordered by fineamount. Note that if the fine amount in node i is equal to theamount in node j, then the node i will be inserted to the left ofthe node j. This function returns the root node of the newtree.
7. def printBonusPolicemen (policeRoot):This function prints the list of police ids which have earned equalto or more than 90% of maximum total fine amount collected by anindividual. The output is pushed to a file called bonus.txt. Theoutput will be in the format
————– Bonus ————-
<license no>, no of violations
8. def destroyPoliceTree (policeRoot):This function is a clean-up function that destroys all the nodes inthe police tree.
9. def printPoliceTree (policeRoot): Thisfunction is meant for debugging purposes. This function prints thecontents of the PoliceTree in-order.
2. Sample file formats
Sample Input file
Every row of the input file should contain the <police id> /<license number> / <fine amount> in the
same sequence. Save the input file as inputPS3.txt
Sample inputPS3.txt
111 / 1231114 / 100
111 / 1214413 / 200
222 / 1231412 / 100
222 / 1231114 / 100
333 / 1231114 / 100
Sample violators.txt
————–Violators————-
1231114, 3
Sample bonus.txt
————–Violators————-
111, 300
222, 100
Expert Answer
Answer to Write an application in Python 3.7 that keeps track of traffic fines. All violations are noted by a traffic policeman in…
OR