Assignment 9, due Oct 30
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!
|_ _| | |- |_ =|
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).
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)
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)