M206 - TMA06 - Question 3
(i) selectedTma: an Integer
1f anInteger references nil, no action is taken. If anInteger is in the range 1 to numberOfTmas, then set selectedTma to anInteger. If anInteger is not in this range, then a dialog box warns the user that no such TMA exists and that selectedTma will not be changed."
- (anInteger=nil)
- if False:[((an Integer>= 1) &(anInteger<=(self numberOfTmas)))
- ifTrue: [selectedTma: = anInteger]
- if False:[Dialog warn:'No such TMA exists, selected TMA will not be changed.']]
- self changed
(ii) retrieveScore
"Returns the score for the TMA referenced by the instance variable selectedTma."
- ^self tmaRecord at:self selectedTMA
(iii) enterScore:anInteger
1f the argument anInteger is a valid TMA score (i.e. it lies between 0 and 100 inclusive), then it is placed in the array tmaRecord at the index referenced by the variable selectedTma, and calculateAverage is used to update the instance variable, average. If anInteger is not a valid TMA score, then the user is warned, and no further action is taken."
- ((anInteger>=0) &(anInteger<=100))
- ifTrue: [tmaRecord at:selectedTma put:anInteger. Self calculateAverage]
- ifFalse:[Dialog warn:'Not a valid TMA score, score not recorded']
- self changed
new
"Use new in the parent class, and initialise in this class in order to create a new initialised instance of class TmaTracker."
^super new initialize
(b)(i) makeList
"Returns a list that corresponds to the TMA numbers for TMAs in the course. This uses the method asList."
- ^((1 to: (self tmaRecord) size) asList)
(ii) doNothing: nothing "Does nothing but update dependants."
- self changed
(c) Properties table for each widget in TmaTrackerGUI.
TmaTrackerGUI Widget Properties |
||
| List Box |
List getter |
MakeList |
| Input/Output Box |
Value getter |
retrieveScore |
| Input/Output Box |
Value getter |
averagedoNothing |
(d)(i) The properties table for the new widget;
Properties table |
||
Check Box |
Label |
Make Read Only |
(ii) The modified instance methods.
Initialize
"Initialises the instance variables."
- Self askForNumberOfTmas.
- Self selectedTma: 1.
- self tmaRecord: ( (Array new: (self numberOfTmas)) atAllPut:O).
- self average:O.
- self make ReadOnly:false
enterScore: an Integer
1f the argument anInteger is a valid TMA score (i.e. it lies between 0 and 100 inclusive), then it is placed in the array tmaRecord at the index referenced by the varMonday, 14 July, 2008 19:30ce variable, average. If anInteger is not a valid TMA score, then the user is warned, and no further action is taken. Also if the screen is set to Read Only notify the user of that fact if he/she tries to enter a score, no further action is taken."
- (Self makeReadOnly = true)
- ifTrue:[Dialog warn:'You are in READ ONLY mode, you cannot enter a score'."Self doNothing:nothing"]
- if False: [((anInteger>=0) &(anInteger<=100))
- ifTrue: [tmaRecord at:selectedTma put:anInteger. Self calculateAverage. Self changed]
- ifFalse:[Dialog warn:'Not a valid TMA score, score not recorded']]