Assignment 10, due Nov 10

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

Assignments are to be turned in on paper. On every assignment, write your name, course and section number at the top. Write your name as it appears in your university records! Use the section number for which you are registered! We will not do detective work to figure out who did what. Work must be legible. Homework is due on paper in discussion section, usually at the start except when the assignment indicates that time to work on the assignment will be provided in class. Exceptions will be made only by advance arrangement with your TA (excepting "acts of God" outside your control). Never push homework under someone's door!

  1. Background: Machine Problem 5 requires, part 2, requires that you create a file called Gate.java containing class Gate and its subsidiary classes.

    a) Which of these classes must be marked as public? (0.2 points)

    b) Which import directives are required? (The answer will be a subset of the list of import directives at the head of the MP4 version of Logic.java.) (0.2 points)

    c) Class Gate includes an abstract method, inputChangeEvent. All subclasses of Gate have outputChangeEvent methods, but class Gate does not have an abstract outputChangeEvent declaration. Why? (0.2 points)

    d) Which classes in file Gate.java can be declared to be final. (you do not need to do this in the code you submit code, but it is harmless to do so.) (0.2 points)

    e) Which methods in the abstract classes in file Gate.java can be declared to be final. (you do not need to do this in the code you submit code, but it is harmless to do so.) (0.2 points)

  2. Background: One of the program transformations discussed in the notes for Lecture 22 (Nov. 7) is to move method parameters to fields of an object, so you pass the parameter by assigning to the field before you call the method. In the posted solution to MP4, we used code like the following code to transfer the input value of a gate to its output:
    if (newVal != value) {
        value = newVal;
        Simulator.schedule(
            time + delay, (float t) -> outputChangeEvent( t )
        );
    }
    

    Scheduling an event that calls a method is not the same thing as calling the method directly, but we can still imagine this code as the result of applying this program transformation. In effect, we have passed a parameter to outputChangeEvent by assigning it to a field of the object and then calling the method.

    a) Give the code for the "original" version of the above code, arrived at by reversing the transformation discussed here. (0.5 points)

    b) As already mentioned, scheduling a method is not the same as calling it. As a result, the transformed code you gave in answer to part a) behaves differently from the code distributed in the assignment. Specifically, it behaves differently with respect to the "low pass filter" requirement of MP5. What is the difference? (0.5 points)

    Notes: If you take the time to understand what's going on, the answer is short! It does not solve MP5, but understanding what is going on here will probably help you with MP5. Experiment and theory may be equally effective in understanding what's going on here.

  3. Background: Look at class Gate in the posted solution to MP4. This class contains a number of Javadoc comments, but some are not very well written.

    a) Some of the elements (fields, inner classes, initializers, methods) of the class do not have Javadoc comments and ought to have them. Which? (0.3 points)

    b) The Javadoc comment on the factory method contains an error. What is missing? (0.3 points)

    c) The Javadoc comments for registerInput and inPinName ought to describe their relationship. Fix these comments so that they correctly explain their relationship. (0.4 points)