Assignment 6, due Oct 9

Part of the homework for CS:2820, Fall 2015
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

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!

  1. Background: In the assignment for MP2, consider the problem of adding a test for logic circuit completeness to the code distributed to the class as a solution to MP1. In that code, each gate has a field called inputList that contains the names of the inputs of that gate that have not yet been used.

    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)

  2. A short question: In the code distributed to the class as a solution to MP1, consider the fields of class Wire. Are there any of these fields that cannot be marked final? Hint: You could just try it and see what happens. (0.5 points)

  3. A short question: In the code distributed to the class as a solution to MP1, there are comments saying: No outside code uses the default initializer. As it turns out, Java includes a mechanism that solves this problem, you can declare an initializer to be private. Write the private initializer for class Gate that prevents any code from outside of class Gate from using the initializer new Gate(). Hint: It is no more than 2 lines of code. (0.5 points)