-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer.py
45 lines (36 loc) · 1.44 KB
/
customer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
File: customer.py
Author: Ken Lambert
Editor: Leigh Stauffer
Project 7
Customer's processing time varies around the average,
so give it a random time between 1 and average time * 2 + 1.
"""
import random
class Customer(object):
"""Represents a customer."""
@classmethod
def generateCustomer(cls, probabilityOfNewArrival,
arrivalTime,
averageTimePerCustomer):
"""Returns a Customer object if the probability
of arrival is greater than or equal to a random number.
Otherwise, returns None, indicating no new customer.
"""
if random.random() <= probabilityOfNewArrival:
return Customer(arrivalTime, averageTimePerCustomer)
else:
return None
def __init__(self, arrivalTime, serviceNeeded):
"""Maintains the arrival time and amount of service needed."""
self._arrivalTime = arrivalTime
self._amountOfServiceNeeded = random.randint(1, serviceNeeded * 2 + 1)
def arrivalTime(self):
"""Returns the arrival time."""
return self._arrivalTime
def amountOfServiceNeeded(self):
"""Returns the amount of service needed."""
return self._amountOfServiceNeeded
def serve(self):
"""Accepts a unit of service from the cashier."""
self._amountOfServiceNeeded -= 1