Assignment 9, due Oct 30

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: Consider adding output gates to a logic simulator, as discussed in the assignment for MP4, with an attempt to display the output of the simulator as a graph going down the page, where each line of output represents one time unit. The display of a simulation with just one output x might look like this:
        |_
         _|
        |
        |-
        |_
         =|
    

    There are numerous forms of output (they are all listed in the assignment for the machine problem). You could select the form of output using a long cascade of if statements such as: If the output used to be false and it is now true and it changed just once, use the string " |_ ".

    A Question: Give a simple algorithm that picks the correct string out of an array of strings using just the current value of this output and the number of changes to this output since the last time it was printed. Note that the previous value of the output need not be tested if the number of output changes is known. (1 point).

  2. Background: In the lecture notes for October 27, three versions of the code to link Road.enter() to Intersection.enter() are given:

    1. Road.enter() schedules both Road.exit() and Intersection.enter() to happen at the same time.

    2. Road.enter() schedules just Road.exit(), and then when Road.exit() is triggered, it schedules Intersection.enter() to happen immediately.

    3. Road.enter() schedules just Road.exit(), and then when Road.exit() is triggered, it directly calls Intersection.enter().

    Suppose we add this code to the very end of Road.exit():

    System.out.println( "Exiting " + this.toString()
            + " at time = " + t
    );
    

    And we add this code to Intersection.enter():

    System.out.println( "Entering " + this.toString()
            + " at time = " + t
    );
    

    A Question: One of the 3 approaches used above guarantees that the exit message will be printed before the enter message. One of the three approaches guarantees that the enter message will be printed before the exit message, and one offers no guarantees because it depends on decisions made elsewhere in the simulator that would be correct in a formal sense for either order. Which of the three leads to which order guarantee? (1.0 points)

  3. A small problem: Find all of the top-level classes and interfaces in the road-network code posted on October 27 (ignore inner classes) and make a class dependenchy diagram, that is, a directed graph with classes at the vertices and arrows from each class to the other classes it depends on. One class depends on another if the dependent class makes any reference to the other class (declaring an instance, using a definition from, referencing a method of, etc.)

    Note: Legibility matters! We strongly suggest that you draw it once just to get the details right, and then redraw your diagram to look nice, with some kind of ordelry arrangement where classes that depend on none of the other classes in this project on top, classes that are codependent in the middle, and classes that depend on them at the bottom. (1.0 points)