Parking Lot OO Design (Python)Python data massagerPython review_generatorPython High Score TablePython Word definition practiceSimple Hangman in PythonBakery - Python 3.4.2Python hexdump generatorOptimizing a Text-To-Speech program with a lot of repetitionPython GPA CalculatorDesign code to compute technical indicators
The baby cries all morning
How to verify if g is a generator for p?
How to be diplomatic in refusing to write code that breaches the privacy of our users
Is exact Kanji stroke length important?
Print name if parameter passed to function
Is there an Impartial Brexit Deal comparison site?
Why is delta-v is the most useful quantity for planning space travel?
How will losing mobility of one hand affect my career as a programmer?
How to avoid InDesign adding pages automatically?
Have I saved too much for retirement so far?
What is the term when two people sing in harmony, but they aren't singing the same notes?
Finding all intervals that match predicate in vector
Why are on-board computers allowed to change controls without notifying the pilots?
How can I replace every global instance of "x[2]" with "x_2"
Best way to store options for panels
Is there any reason not to eat food that's been dropped on the surface of the moon?
How can my private key be revealed if I use the same nonce while generating the signature?
Is there a problem with hiding "forgot password" until it's needed?
What are the ramifications of creating a homebrew world without an Astral Plane?
What is the oldest known work of fiction?
quarter to five p.m
Find swapfile location in Linux Mint
What defines a dissertation?
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
Parking Lot OO Design (Python)
Python data massagerPython review_generatorPython High Score TablePython Word definition practiceSimple Hangman in PythonBakery - Python 3.4.2Python hexdump generatorOptimizing a Text-To-Speech program with a lot of repetitionPython GPA CalculatorDesign code to compute technical indicators
$begingroup$
Please review my code for parking lot design.
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-3.x
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$
add a comment |
$begingroup$
Please review my code for parking lot design.
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-3.x
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$
add a comment |
$begingroup$
Please review my code for parking lot design.
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-3.x
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.
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-3.x
python-3.x
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.
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 11 mins ago
Savita RanaSavita Rana
1
1
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.
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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