Assignment 8, due Oct 23

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 a logic simulator, when the simulation is started, all of the inputs to all of the gates are false, and all of the outputs are false. If false is encoded electronically with zero volts and true with some non-zero value, this corresponds to the state of the system when the power is turned on, before any of the gates have had time to react to their inputs.

    Recall that logic gates have an inherent delay, the time it takes for a change in the input to percolate through the gate to change the output.

    a) Supposing that there are just 3 types of gates in your simulation, and, or and not, which of these would need to change their output shortly after the simulation is started, and when would the output change. (0.5 points)

    b) Suggest where in the simulation program the initial events could be scheduled. (There are several options, you need only identify one that will work). (0.5 points)

  2. A short scavanger hunt question: What is a checked exception? (0.5 points)

  3. A small problem: In the notes for Oct. 15, there is a discussion of how the class ListQueue can be implemented in Java. The only methods given are enqueue() and dequeue. Give code for the method indexOf(o), where this method is defined identically to the method by that name in Java's class LinkedList. (0.5 points)

  4. Background: In order to be able to schedule events, you need some kind of priority queue of events. Each event in that queue will, when its turn comes, call a method of one of the simulation routines. There are lots of ways of doing this. In the vehicle network simulation code distributed on Oct. 15, this bug notice appeared in Road.enter():
    // Bug: must schedule this.exit( v, t + travelTime )
    

    Consider rewriting this as follows:

            Simulator.schedule(
    		t + travelTime,
    		(float time) -> this.exit( v, time )
    	);
    

    Inside class Simulator, the following bits of code occur

    	public void schedule( float time, Action a ) { ... }
    	...
    	        a.trigger( time )
    

    a) The second argument to this method call uses Java's version of lambda notation. Given what you can infer about class class Action above, rewrite the call to Simulator.schedule() using explicit named classes and objects instead of anonymous classes and objects. (1.0 points)