M206 - TMA06 Question 1
a) chosenNumber
If chosenNumber references nil, set chosenNumber to 1
(i,e. initialise it). Return chosenNumber."
- (chosenNumber = isNil)
- ifTrue: {self chosenNumber:=1].
- ^ chosenNumber
(ii) chosenNumber:anInteger
"Check that anInteger is a valid lottery number, i.e. that it is an integer and that it lies between 1 and 50, inclusive. If it is valid, set chosenNumber to anInteger. If it isn't valid, a dialogue box warns the user that it isn't, and no further action is taken."
- ((anInteger class = isInteger) & (anInteger>=1) & (anInteger<=50))
- ifTrue: [chosen Number: =anInteger]
- ifFalse:[Dialog warn:'You have chosen an invalid number!']
- self changed
(b) The properties table
Properties Table |
||
action button |
Label Action selector |
zeroise zeroise |
action button |
Label Action selector |
randomise randomise |
action button |
Label Action selector |
increment increment |
slider |
Number getter Number setter Start Step Stop |
chosenNumber chosenNumber: 1 1 50 |
input/output box |
Value getter Value setter type |
chosenNumber chosenNumber number |
(c) If a non-valid lottery number is added using the input/output box, on pressing return the Dialog box and the warning is shown, on clicking Ok the value is restored to its original value, the slider position does not change during any part of this operation. Since 1 have set the range of my slider to be 1 to 50 inclusive it is not possible to enter an invalid number using the slider.
(d) returnFrequency
"Returns the number of times a particular number referenced by chosenNumber has been drawn in the lottery"
- ^self frequencyDrawn at:self chosenNumber
(e)(i) doNothing: nothing
"Does nothing except updating user interfaces."
^self changed
(ii) Property table for frequencyDrawn widget.
frequencyDrawn box |
Value getter |
returnFrequency |
(f)(i) zeroize
"Set the frequency of all bails to 0'
- super zeroise.
- Self frequencyDrawn at: 13 put:5.
- self changed
(ii) The LotteryGUI will support an instance of FixedLottery because the only difference between the two Lottery classes is the way in which they are zeroised, the difference being FixedLottery has its ball 13 set to 5 at zeroize instead of zero. All methods in GUI supported due to FixedLottery inheriting the necessary protocol.