Machine Problem 6, due Dec. 11
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!
This is not a real machine problem, but it is worth 5 points and it will be graded as if it was MP6.
In Lecture 26 on Dec. 3, we solved this problem in a completely different way, although we did not apply this solution to the road network simulation.
a) Give code for the non-static version of ExitIntersectionEvent. (0.5 points)
b) Give code for the "crutch" that allows its initializer to be called from outside class Vehicle. (0.5 points)
c) And give the code to call the initializer from NoStops.enter(). (0.5 points)
Note: This is mostly cut and paste work, once you figure out the necessary material. It was all covered in class.
A problem: Consider all of the fields and methods in class Road. Which of these fields and methods belong in the general purpose class Road and which would belong in RoadSimulation because they are specific to a discrete-event simulation of a road? (1.0 points).
class C { private int f = 0; // some field of the object public int m( int g, int h ) { // method m int t; t = f; f = g + h; return t; } } // somewhere else in the program C o; // o is an object of class C i = o.m(5, 6); // apply the method C.m to o
a) Rewrite the code for class c to eliminate all parameter passing and all nonvoid return values, using transformations of the sort discussed in the lectures of Dec. 1 and 3. (0.5 points)
b) Rewrite the code for the call to o.m() to call your modified code from part a. (0.5 points)
A question: How (focusing on object orientation) would you go about making the syntax of the destination connection wired to the input of a gate depend on the type of gate? Do not give code! Describe your design. (1.0 points)