Assignment 6, due Oct 9
Part of
the homework for CS:2820, Fall 2015
|
On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!
a) Suggest complete code for an isComplete() method you could add to the class gate to test whether the inputs to that gate were completely defined. Don't bother with comments, the whole method is only 3 lines of code (with a large number of possible middle lines). For this part, assume no other parts of MP2 are to be solved. (0.5 points)
b) Now, suppose we used the ordinal position of the input name in inputList in order to compute the corresponding input number. Explain (briefly) how this idea is in conflict with the version of isComplete() discussed above. (0.5 points)
c) Suppose we make inputList read-only (that is, we never change any attributes of inputList after it is initialised. This lets us use the ordinal position of a list element as the input number, but it prevents us from keeping the implementation of isComplete() from MP1. Suggest, briefly in no more than one or two sentences, an alternative implementation of isComplete(). (0.5 points)
d) Does the final keyword, applied to the declaration of inputList() prevent accidental modification that would violate the constraint on which part c) above is predecated? (0.5 points)