Object subclass: #LottoCustomer
  instanceVariableNames: 'tickets money won cost lottery'
  classVariableNames: '' poolDictionaries: ''    !

!LottoCustomer class methods !
 
new: aNumber
    ^ super new initialize: aNumber!

example
    ^ (self new: 5000.0) lottery: (Lottery example)! !

!LottoCustomer methods !

initialize: aNumber
    tickets := Bag new.  money := aNumber.  won := 0.0.  cost := 0.0.!

tickets
    ^Bag new addAll: tickets!

winnings
    ^won - cost!

lottery: aLottery
    lottery := aLottery!

lottery
    ^ lottery!

balance
    ^ money - cost + won!

play: numTimes
    | ud t |
    ud := UniformDiscrete new: lottery range.
    numTimes timesRepeat:
          [ (self balance < lottery ticketCost)
                ifTrue: [^self].
            self playTicket:
                ((Ticket new) initialize: (ud pick: lottery numsPerTicket))]!

playTicket: aTicket
    cost := cost + lottery ticketCost.
    tickets add: aTicket.
    won := won + (lottery winnings: aTicket)! !
