- Notifications
You must be signed in to change notification settings - Fork360
Added Parking lot system file#255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
157 changes: 157 additions & 0 deletionsParkingLot-master/LowLevel_ParkingSystem.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| import Vehicle | ||
| import argparse | ||
| import sys | ||
| if sys.version_info[0] == 2: | ||
| input = raw_input | ||
| class ParkingLot: | ||
| def __init__(self): | ||
| self.capacity = 0 | ||
| self.slotid = 0 | ||
| self.numOfOccupiedSlots = 0 | ||
| def createParkingLot(self,capacity): | ||
| self.slots = [-1] * capacity | ||
| self.capacity = capacity | ||
| return self.capacity | ||
| def getEmptySlot(self): | ||
| for i in range(len(self.slots)): | ||
| if self.slots[i] == -1: | ||
| return i | ||
| def park(self,regno,color): | ||
| if self.numOfOccupiedSlots < self.capacity: | ||
| slotid = self.getEmptySlot() | ||
| self.slots[slotid] = Vehicle.Car(regno,color) | ||
| self.slotid = self.slotid+1 | ||
| self.numOfOccupiedSlots = self.numOfOccupiedSlots + 1 | ||
| return slotid+1 | ||
| else: | ||
| return -1 | ||
| def leave(self,slotid): | ||
| if self.numOfOccupiedSlots > 0 and self.slots[slotid-1] != -1: | ||
| self.slots[slotid-1] = -1 | ||
| self.numOfOccupiedSlots = self.numOfOccupiedSlots - 1 | ||
| return True | ||
| else: | ||
| return False | ||
| def status(self): | ||
| print("Slot No.\tRegistration No.\tColour") | ||
| for i in range(len(self.slots)): | ||
| if self.slots[i] != -1: | ||
| print(str(i+1) + "\t\t" +str(self.slots[i].regno) + "\t\t" + str(self.slots[i].color)) | ||
| else: | ||
| continue | ||
| def getRegNoFromColor(self,color): | ||
| regnos = [] | ||
| for i in self.slots: | ||
| if i == -1: | ||
| continue | ||
| if i.color == color: | ||
| regnos.append(i.regno) | ||
| return regnos | ||
| def getSlotNoFromRegNo(self,regno): | ||
| for i in range(len(self.slots)): | ||
| if self.slots[i].regno == regno: | ||
| return i+1 | ||
| else: | ||
| continue | ||
| return -1 | ||
| def getSlotNoFromColor(self,color): | ||
| slotnos = [] | ||
| for i in range(len(self.slots)): | ||
| if self.slots[i] == -1: | ||
| continue | ||
| if self.slots[i].color == color: | ||
| slotnos.append(str(i+1)) | ||
| return slotnos | ||
| def show(self,line): | ||
| if line.startswith('create_parking_lot'): | ||
| n = int(line.split(' ')[1]) | ||
| res = self.createParkingLot(n) | ||
| print('Created a parking lot with '+str(res)+' slots') | ||
| elif line.startswith('park'): | ||
| regno = line.split(' ')[1] | ||
| color = line.split(' ')[2] | ||
| res = self.park(regno,color) | ||
| if res == -1: | ||
| print("Sorry, parking lot is full") | ||
| else: | ||
| print('Allocated slot number: '+str(res)) | ||
| elif line.startswith('leave'): | ||
| leave_slotid = int(line.split(' ')[1]) | ||
| status = self.leave(leave_slotid) | ||
| if status: | ||
| print('Slot number '+str(leave_slotid)+' is free') | ||
| elif line.startswith('status'): | ||
| self.status() | ||
| elif line.startswith('check_car_number_with_carcolor'): | ||
| color = line.split(' ')[1] | ||
| regnos = self.getRegNoFromColor(color) | ||
| print(', '.join(regnos)) | ||
| elif line.startswith('check_slot_number_with_carcolor'): | ||
| color = line.split(' ')[1] | ||
| slotnos = self.getSlotNoFromColor(color) | ||
| print(', '.join(slotnos)) | ||
| elif line.startswith('check_slot_number_with_carno'): | ||
| regno = line.split(' ')[1] | ||
| slotno = self.getSlotNoFromRegNo(regno) | ||
| if slotno == -1: | ||
| print("Not found") | ||
| else: | ||
| print(slotno) | ||
| elif line.startswith('exit'): | ||
| exit(0) | ||
| def main(): | ||
| parkinglot = ParkingLot() | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('-f', action="store", required=False, dest='src_file', help="Input File") | ||
| args = parser.parse_args() | ||
| if args.src_file: | ||
| with open(args.src_file) as f: | ||
| for line in f: | ||
| line = line.rstrip('\n') | ||
| parkinglot.show(line) | ||
| else: | ||
| while True: | ||
| line = input("$ ") | ||
| parkinglot.show(line) | ||
| if __name__ == '__main__': | ||
| print("----------Welcome to Low Level Parking Lot System-----------------") | ||
| print("Type following commands to perform operations on Parking system") | ||
| print("1. create_parking_lot n (n=capacity)") | ||
| print("2. park car_number var_color") | ||
| print("3. status") | ||
| print("4. leave x (x=slot number)") | ||
| print("5. check_car_number_with_carcolor car_color") | ||
| print("6. check_slot_number_with_carcolor car_color") | ||
| print("7. check_slot_number_with_carno car_no") | ||
| print("Exit") | ||
| print("-------------------------------------------------------------------") | ||
| main() |
Binary file addedParkingLot-master/Parking_lot_Eeshan_Demo.pptx
Binary file not shown.
12 changes: 12 additions & 0 deletionsParkingLot-master/Vehicle.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| class Vehicle: | ||
| def __init__(self,regno,color): | ||
| self.color = color | ||
| self.regno = regno | ||
| class Car(Vehicle): | ||
| def __init__(self,regno,color): | ||
| Vehicle.__init__(self,regno,color) | ||
| def getType(self): | ||
| return "Car" |
Binary file not shown.
15 changes: 15 additions & 0 deletionsParkingLot-master/run_test_case.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| create_parking_lot 6 | ||
| park MH-12-LM-7754 white | ||
| park GJ-11-FM-3421 white | ||
| park DL-01-KL-0786 black | ||
| park JH-04-AK-8654 red | ||
| park MH-12-TR-6636 blue | ||
| park KA-01-AR-2342 black | ||
| leave 4 | ||
| status | ||
| park KA-01-P-333 white | ||
| park DL-12-AA-9999 white | ||
| check_car_number_with_carcolor white | ||
| check_slot_number_with_carcolor white | ||
| check_slot_number_with_carno MH-12-LM-7754 | ||
| check_slot_number_with_carno KA-01-AR-2342 |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.