added some samples
[k8lst.git] / samples / simul / store01.st
blobf68066823714ab144fde12d42cec28b3a13b84c1
1 Requires [ simulation ]
4 class: Customer [
5   numberOfScoops [
6     | num |
7     num := SmallInt atRandom % 3 + 1.
8     'customer has ' print. num print. ' scoop' print.
9     num > 1 ifTrue: [ 's' print ].
10     '.' printNl.
11     ^num
12   ]
16 Simulation subclass: IceCreamStore [
17   | profit |
19   ^new [
20     | obj |
21     obj := super new.
22     self in: obj var: #profit put: 0.0.
23     obj sheduleArrival.
24     ^obj
25   ]
27   sheduleArrival [
28     self addEvent: Customer new at: (self time + (SmallInt atRandom % 5 + 1))
29   ]
31   reportProfits [
32     'profits are ' print. profit print. '.' printNl.
33   ]
35   processEvent: event [
36     'customer received at ' print. self time print. '.' printNl.
37     profit := profit + (event numberOfScoops asFloat * 0.17).
38     self sheduleArrival
39   ]
44   | store |
45   store := IceCreamStore new.
46   [ store time < 15 ] whileTrue: [ store proceed ].
47   store reportProfits.