Assignment 7, due Oct 16
Part of
the homework for CS:2820, Fall 2015
|
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!
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)
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)
A question: For each operation above, document the corresponding Java linked list method. (0.5 points)
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)