Assignment 8, due Oct 23
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!
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)
// 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)