Parking Lot OO Design (Python)












3












$begingroup$


Please review my code for parking lot design.
I am new to OOD concepts, It will be great to have some feedback on OO Structure of the solution.



Requirements considered:




  1. The parking lot can have multiple levels.

  2. Each level can have 'compact', 'large', 'bike' and 'electric' spots.

  3. Vehicle should be charged according to spot type, time of parking and duration of parking.

  4. Should be able to add more spots to level.

  5. Show the available number of spots on each level.


class parkingFloor():
def __init__(self,name):
self.name = name
self.spotTotal = {'compact':0,'large':0,'bike':0,'electric':0}

self.spotTaken = {'compact':0,'large':0,'bike':0,'electric':0}

self.freeSpot = {'compact':set(),'large':set(),'bike':set(),'electric':set()}
self.takenSpot = {'compact':{},'large':{},'bike':{},'electric':{}}

def assignSpot(self,tickt):
if self.spotTaken[tickt.veh.type] >= self.spotTotal[tickt.veh.type]:
return False
for s in self.freeSpot[tickt.veh.type]:
if s.id not in self.takenSpot[tickt.veh.type]:
self.takenSpot[tickt.veh.type][s.id] = tickt
self.spotTaken[tickt.veh.type]+=1
self.freeSpot[tickt.veh.type].remove(s)
tickt.allocateSpot(s)
return True
return False

def addSpot(self,type,v):
for i in range(v):
s = spot(type)
self.freeSpot[type].add(s)
self.spotTotal[type] += v

class entryPanel():
def __init__(self,id):
self.id = id

def printTicket(self,tickt):
print('Vehicle ID ',tickt.veh.id)
print('Spot ID ',tickt.spot.id)
print('Ticket ID ',tickt.id)
print('Date Time',tickt.DateTime)

def display(self,message):
print(message)


class vehicle():
def __init__(self,id,vehType):
self.id = id
self.type = vehType


class spot():
def __init__(self,spotType):
def generateId():
# some mechanism to generate spot id
return 1
self.id = generateId()
self.type = spotType



class ticket():
def __init__(self,v1):
self.id = self.generateId()
self.veh = v1

self.spot = None
self.DateTime = self.getTime()
self.amount = 0
self.status = 'Active'
self.payment = None

def getTime(self):
time = 1234
return time

def generateId(self):
# some mechanism to generate new ticket id
new_ticket = 1
return new_ticket

def allocateSpot(self,spot):
self.spot = spot

def addPayment(self,pay):
self.status = 'Complete'
self.payment = pay

class parkingLot():
def __init__(self,name,address):
self.name = name
self.address = address
self.level =

def addLevel(self,floor):
self.level.append(floor)

def processEntry(self,t1,gate):
for l in self.level:
if l.assignSpot(t1):
gate.printTicket(t1)
return
gate.display('No Spot Empty')

def processExit(self,tickt,gate):
def getTime():
# Gives the current time
return 3
currTime = getTime()
print('Processing fare',tickt.veh.type,tickt.spot.id,tickt.DateTime,currTime)
amountCalculated = 7
tickt.addPayment(Payment(amountCalculated))
gate.display('Payment Successful')

class Payment():
def __init__(self,amount):
self.id = 'paymentid2'
self.type = 'credit' # debit
self.time = 'paymet time'

class displayBoard():
def show(self,p):
for l in p.level:
print(l.name)
for k in l.spotTotal.keys():
print(k, l.spotTotal[k] - l.spotTaken[k])


P = parkingLot('Savita','Address')
floor1 = parkingFloor('floor1')
P.addLevel(floor1)
floor1.addSpot('compact',5)

board = displayBoard()
board.show(P)

entryPanel1 = entryPanel('1')

v1 = vehicle(1,'compact')
t1 = ticket(v1)

P.processEntry(t1,entryPanel1)
P.processExit(t1,entryPanel1)










share|improve this question









New contributor




Savita Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$








  • 1




    $begingroup$
    Welcome to Code Review! You've posted a lot of code to review. Consider giving the reviewers a hint where the focus of the review should be (e.g. style, clarity, OO structure, ...). Also elaborate on what the expected outcome of the provided test code should be.
    $endgroup$
    – Alex
    9 hours ago










  • $begingroup$
    get some feedback on the OO structure of the solution I shared don't comment comments asking for clarification or additional information: edit your post.
    $endgroup$
    – greybeard
    8 hours ago
















3












$begingroup$


Please review my code for parking lot design.
I am new to OOD concepts, It will be great to have some feedback on OO Structure of the solution.



Requirements considered:




  1. The parking lot can have multiple levels.

  2. Each level can have 'compact', 'large', 'bike' and 'electric' spots.

  3. Vehicle should be charged according to spot type, time of parking and duration of parking.

  4. Should be able to add more spots to level.

  5. Show the available number of spots on each level.


class parkingFloor():
def __init__(self,name):
self.name = name
self.spotTotal = {'compact':0,'large':0,'bike':0,'electric':0}

self.spotTaken = {'compact':0,'large':0,'bike':0,'electric':0}

self.freeSpot = {'compact':set(),'large':set(),'bike':set(),'electric':set()}
self.takenSpot = {'compact':{},'large':{},'bike':{},'electric':{}}

def assignSpot(self,tickt):
if self.spotTaken[tickt.veh.type] >= self.spotTotal[tickt.veh.type]:
return False
for s in self.freeSpot[tickt.veh.type]:
if s.id not in self.takenSpot[tickt.veh.type]:
self.takenSpot[tickt.veh.type][s.id] = tickt
self.spotTaken[tickt.veh.type]+=1
self.freeSpot[tickt.veh.type].remove(s)
tickt.allocateSpot(s)
return True
return False

def addSpot(self,type,v):
for i in range(v):
s = spot(type)
self.freeSpot[type].add(s)
self.spotTotal[type] += v

class entryPanel():
def __init__(self,id):
self.id = id

def printTicket(self,tickt):
print('Vehicle ID ',tickt.veh.id)
print('Spot ID ',tickt.spot.id)
print('Ticket ID ',tickt.id)
print('Date Time',tickt.DateTime)

def display(self,message):
print(message)


class vehicle():
def __init__(self,id,vehType):
self.id = id
self.type = vehType


class spot():
def __init__(self,spotType):
def generateId():
# some mechanism to generate spot id
return 1
self.id = generateId()
self.type = spotType



class ticket():
def __init__(self,v1):
self.id = self.generateId()
self.veh = v1

self.spot = None
self.DateTime = self.getTime()
self.amount = 0
self.status = 'Active'
self.payment = None

def getTime(self):
time = 1234
return time

def generateId(self):
# some mechanism to generate new ticket id
new_ticket = 1
return new_ticket

def allocateSpot(self,spot):
self.spot = spot

def addPayment(self,pay):
self.status = 'Complete'
self.payment = pay

class parkingLot():
def __init__(self,name,address):
self.name = name
self.address = address
self.level =

def addLevel(self,floor):
self.level.append(floor)

def processEntry(self,t1,gate):
for l in self.level:
if l.assignSpot(t1):
gate.printTicket(t1)
return
gate.display('No Spot Empty')

def processExit(self,tickt,gate):
def getTime():
# Gives the current time
return 3
currTime = getTime()
print('Processing fare',tickt.veh.type,tickt.spot.id,tickt.DateTime,currTime)
amountCalculated = 7
tickt.addPayment(Payment(amountCalculated))
gate.display('Payment Successful')

class Payment():
def __init__(self,amount):
self.id = 'paymentid2'
self.type = 'credit' # debit
self.time = 'paymet time'

class displayBoard():
def show(self,p):
for l in p.level:
print(l.name)
for k in l.spotTotal.keys():
print(k, l.spotTotal[k] - l.spotTaken[k])


P = parkingLot('Savita','Address')
floor1 = parkingFloor('floor1')
P.addLevel(floor1)
floor1.addSpot('compact',5)

board = displayBoard()
board.show(P)

entryPanel1 = entryPanel('1')

v1 = vehicle(1,'compact')
t1 = ticket(v1)

P.processEntry(t1,entryPanel1)
P.processExit(t1,entryPanel1)










share|improve this question









New contributor




Savita Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$








  • 1




    $begingroup$
    Welcome to Code Review! You've posted a lot of code to review. Consider giving the reviewers a hint where the focus of the review should be (e.g. style, clarity, OO structure, ...). Also elaborate on what the expected outcome of the provided test code should be.
    $endgroup$
    – Alex
    9 hours ago










  • $begingroup$
    get some feedback on the OO structure of the solution I shared don't comment comments asking for clarification or additional information: edit your post.
    $endgroup$
    – greybeard
    8 hours ago














3












3








3


1



$begingroup$


Please review my code for parking lot design.
I am new to OOD concepts, It will be great to have some feedback on OO Structure of the solution.



Requirements considered:




  1. The parking lot can have multiple levels.

  2. Each level can have 'compact', 'large', 'bike' and 'electric' spots.

  3. Vehicle should be charged according to spot type, time of parking and duration of parking.

  4. Should be able to add more spots to level.

  5. Show the available number of spots on each level.


class parkingFloor():
def __init__(self,name):
self.name = name
self.spotTotal = {'compact':0,'large':0,'bike':0,'electric':0}

self.spotTaken = {'compact':0,'large':0,'bike':0,'electric':0}

self.freeSpot = {'compact':set(),'large':set(),'bike':set(),'electric':set()}
self.takenSpot = {'compact':{},'large':{},'bike':{},'electric':{}}

def assignSpot(self,tickt):
if self.spotTaken[tickt.veh.type] >= self.spotTotal[tickt.veh.type]:
return False
for s in self.freeSpot[tickt.veh.type]:
if s.id not in self.takenSpot[tickt.veh.type]:
self.takenSpot[tickt.veh.type][s.id] = tickt
self.spotTaken[tickt.veh.type]+=1
self.freeSpot[tickt.veh.type].remove(s)
tickt.allocateSpot(s)
return True
return False

def addSpot(self,type,v):
for i in range(v):
s = spot(type)
self.freeSpot[type].add(s)
self.spotTotal[type] += v

class entryPanel():
def __init__(self,id):
self.id = id

def printTicket(self,tickt):
print('Vehicle ID ',tickt.veh.id)
print('Spot ID ',tickt.spot.id)
print('Ticket ID ',tickt.id)
print('Date Time',tickt.DateTime)

def display(self,message):
print(message)


class vehicle():
def __init__(self,id,vehType):
self.id = id
self.type = vehType


class spot():
def __init__(self,spotType):
def generateId():
# some mechanism to generate spot id
return 1
self.id = generateId()
self.type = spotType



class ticket():
def __init__(self,v1):
self.id = self.generateId()
self.veh = v1

self.spot = None
self.DateTime = self.getTime()
self.amount = 0
self.status = 'Active'
self.payment = None

def getTime(self):
time = 1234
return time

def generateId(self):
# some mechanism to generate new ticket id
new_ticket = 1
return new_ticket

def allocateSpot(self,spot):
self.spot = spot

def addPayment(self,pay):
self.status = 'Complete'
self.payment = pay

class parkingLot():
def __init__(self,name,address):
self.name = name
self.address = address
self.level =

def addLevel(self,floor):
self.level.append(floor)

def processEntry(self,t1,gate):
for l in self.level:
if l.assignSpot(t1):
gate.printTicket(t1)
return
gate.display('No Spot Empty')

def processExit(self,tickt,gate):
def getTime():
# Gives the current time
return 3
currTime = getTime()
print('Processing fare',tickt.veh.type,tickt.spot.id,tickt.DateTime,currTime)
amountCalculated = 7
tickt.addPayment(Payment(amountCalculated))
gate.display('Payment Successful')

class Payment():
def __init__(self,amount):
self.id = 'paymentid2'
self.type = 'credit' # debit
self.time = 'paymet time'

class displayBoard():
def show(self,p):
for l in p.level:
print(l.name)
for k in l.spotTotal.keys():
print(k, l.spotTotal[k] - l.spotTaken[k])


P = parkingLot('Savita','Address')
floor1 = parkingFloor('floor1')
P.addLevel(floor1)
floor1.addSpot('compact',5)

board = displayBoard()
board.show(P)

entryPanel1 = entryPanel('1')

v1 = vehicle(1,'compact')
t1 = ticket(v1)

P.processEntry(t1,entryPanel1)
P.processExit(t1,entryPanel1)










share|improve this question









New contributor




Savita Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




Please review my code for parking lot design.
I am new to OOD concepts, It will be great to have some feedback on OO Structure of the solution.



Requirements considered:




  1. The parking lot can have multiple levels.

  2. Each level can have 'compact', 'large', 'bike' and 'electric' spots.

  3. Vehicle should be charged according to spot type, time of parking and duration of parking.

  4. Should be able to add more spots to level.

  5. Show the available number of spots on each level.


class parkingFloor():
def __init__(self,name):
self.name = name
self.spotTotal = {'compact':0,'large':0,'bike':0,'electric':0}

self.spotTaken = {'compact':0,'large':0,'bike':0,'electric':0}

self.freeSpot = {'compact':set(),'large':set(),'bike':set(),'electric':set()}
self.takenSpot = {'compact':{},'large':{},'bike':{},'electric':{}}

def assignSpot(self,tickt):
if self.spotTaken[tickt.veh.type] >= self.spotTotal[tickt.veh.type]:
return False
for s in self.freeSpot[tickt.veh.type]:
if s.id not in self.takenSpot[tickt.veh.type]:
self.takenSpot[tickt.veh.type][s.id] = tickt
self.spotTaken[tickt.veh.type]+=1
self.freeSpot[tickt.veh.type].remove(s)
tickt.allocateSpot(s)
return True
return False

def addSpot(self,type,v):
for i in range(v):
s = spot(type)
self.freeSpot[type].add(s)
self.spotTotal[type] += v

class entryPanel():
def __init__(self,id):
self.id = id

def printTicket(self,tickt):
print('Vehicle ID ',tickt.veh.id)
print('Spot ID ',tickt.spot.id)
print('Ticket ID ',tickt.id)
print('Date Time',tickt.DateTime)

def display(self,message):
print(message)


class vehicle():
def __init__(self,id,vehType):
self.id = id
self.type = vehType


class spot():
def __init__(self,spotType):
def generateId():
# some mechanism to generate spot id
return 1
self.id = generateId()
self.type = spotType



class ticket():
def __init__(self,v1):
self.id = self.generateId()
self.veh = v1

self.spot = None
self.DateTime = self.getTime()
self.amount = 0
self.status = 'Active'
self.payment = None

def getTime(self):
time = 1234
return time

def generateId(self):
# some mechanism to generate new ticket id
new_ticket = 1
return new_ticket

def allocateSpot(self,spot):
self.spot = spot

def addPayment(self,pay):
self.status = 'Complete'
self.payment = pay

class parkingLot():
def __init__(self,name,address):
self.name = name
self.address = address
self.level =

def addLevel(self,floor):
self.level.append(floor)

def processEntry(self,t1,gate):
for l in self.level:
if l.assignSpot(t1):
gate.printTicket(t1)
return
gate.display('No Spot Empty')

def processExit(self,tickt,gate):
def getTime():
# Gives the current time
return 3
currTime = getTime()
print('Processing fare',tickt.veh.type,tickt.spot.id,tickt.DateTime,currTime)
amountCalculated = 7
tickt.addPayment(Payment(amountCalculated))
gate.display('Payment Successful')

class Payment():
def __init__(self,amount):
self.id = 'paymentid2'
self.type = 'credit' # debit
self.time = 'paymet time'

class displayBoard():
def show(self,p):
for l in p.level:
print(l.name)
for k in l.spotTotal.keys():
print(k, l.spotTotal[k] - l.spotTaken[k])


P = parkingLot('Savita','Address')
floor1 = parkingFloor('floor1')
P.addLevel(floor1)
floor1.addSpot('compact',5)

board = displayBoard()
board.show(P)

entryPanel1 = entryPanel('1')

v1 = vehicle(1,'compact')
t1 = ticket(v1)

P.processEntry(t1,entryPanel1)
P.processExit(t1,entryPanel1)







python python-3.x object-oriented






share|improve this question









New contributor




Savita Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Savita Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 7 hours ago







Savita Rana













New contributor




Savita Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 9 hours ago









Savita RanaSavita Rana

213




213




New contributor




Savita Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Savita Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Savita Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    $begingroup$
    Welcome to Code Review! You've posted a lot of code to review. Consider giving the reviewers a hint where the focus of the review should be (e.g. style, clarity, OO structure, ...). Also elaborate on what the expected outcome of the provided test code should be.
    $endgroup$
    – Alex
    9 hours ago










  • $begingroup$
    get some feedback on the OO structure of the solution I shared don't comment comments asking for clarification or additional information: edit your post.
    $endgroup$
    – greybeard
    8 hours ago














  • 1




    $begingroup$
    Welcome to Code Review! You've posted a lot of code to review. Consider giving the reviewers a hint where the focus of the review should be (e.g. style, clarity, OO structure, ...). Also elaborate on what the expected outcome of the provided test code should be.
    $endgroup$
    – Alex
    9 hours ago










  • $begingroup$
    get some feedback on the OO structure of the solution I shared don't comment comments asking for clarification or additional information: edit your post.
    $endgroup$
    – greybeard
    8 hours ago








1




1




$begingroup$
Welcome to Code Review! You've posted a lot of code to review. Consider giving the reviewers a hint where the focus of the review should be (e.g. style, clarity, OO structure, ...). Also elaborate on what the expected outcome of the provided test code should be.
$endgroup$
– Alex
9 hours ago




$begingroup$
Welcome to Code Review! You've posted a lot of code to review. Consider giving the reviewers a hint where the focus of the review should be (e.g. style, clarity, OO structure, ...). Also elaborate on what the expected outcome of the provided test code should be.
$endgroup$
– Alex
9 hours ago












$begingroup$
get some feedback on the OO structure of the solution I shared don't comment comments asking for clarification or additional information: edit your post.
$endgroup$
– greybeard
8 hours ago




$begingroup$
get some feedback on the OO structure of the solution I shared don't comment comments asking for clarification or additional information: edit your post.
$endgroup$
– greybeard
8 hours ago










0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Savita Rana is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216290%2fparking-lot-oo-design-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








Savita Rana is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Savita Rana is a new contributor. Be nice, and check out our Code of Conduct.













Savita Rana is a new contributor. Be nice, and check out our Code of Conduct.












Savita Rana is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216290%2fparking-lot-oo-design-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to make a Squid Proxy server?

Is this a new Fibonacci Identity?

Touch on Surface Book