Assignment 7, due Oct 16

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 these two sets of definitions:
                                  class D {
    class C {                             private int i = 0;
            public int i = 0;             public int getI() { return i; }
    }                                     public int setI(int v) { i = v; }
                                          }
                                  }
    C cc = new C();               D dd = new D();
    

    These seem equal, in the sense that cc.i=5 is comparable to dd.setI(5) and x=cc.i is comparable to x=dd.getI(). Our goal is to create an interface specification, such that one of these classes can be declared to be an implementation of that interface.

    a) One of these does not permit such an interface to be constructed, explain why. (0.2 points)

    b) Give the interface definition that one of these can be declared to implement. (0.4 points)

    c) Rewrite one of these so that it explicitly declares itself as an implementation of that interface. (0.4 points)

  2. A short scavanger hunt question: In the reading assignments for this week's classes, there is a discussion that comes very close to discussing what could be a framework for a discrete-event simulation system, in which events are scheduled to happen at specific times in an event list. On what pages is this example discussed? (0.5 points)

  3. Background: You take a job with the Iowa State Lottery and find that your predecessor left notes indicating that he was not satisfied with the pseudo-random number generator that the lottery was using. He proposed the following code:
    import java.util.Random;
    
    class PRNG {
    	/** Pseudo-Random Number Generator for simulation model.
             */
            private static Random r = new Random();
    
            public static randInt( int n ) {
    		/** Draw an integer in the range 0 <= i < n from the stream.
    		 *  But first, draw a random number of entries form the stream
    		 *  in order to make the result more random.
                     */
    		for (int i = r.nextInt( 10 ); i > 0; i--) r.nextInt();
                    return r.nextInt( n );
            }
    }
    

    A question: Does this indeed create a result that is more random than the built-in Java pseudo-random number stream? Give reasoning to support your conclusion. (0.5 points)

  4. Background: A double-ended queue (or DEQ, pronounced dek) is a queue with the following operations: insert-head(i) and insert-tail(i), which add the item i to either the head or the tail of the queue, and i=get-head() and i=get-tail() which remove and return the head or tail element of the queue. Each of these corresponds to a standard method on a Java linked list.

    A question: For each operation above, document the corresponding Java linked list method. (0.5 points)

  5. Background: Look at the analysis of the basic events that will drive the road network simulation from the notes for Oct. 13. Note that these events on the classes for roads and intersections are significantly more complex than the events for a logic simulator.

    A question: What are the key events on the classes for wires and gates in a logic simulator? This question is to getting you started on MP3. (0.5 points)