Machine Problem 6, due Dec. 11

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!

This is not a real machine problem, but it is worth 5 points and it will be graded as if it was MP6.

  1. Background: In lecture 24 on Nov. 19, we ran up against a brick wall trying to write code that called new v1.exitIntersectionEvent() (we also tried v1.new ExitIntersectionEvent()), where v1 is a specific Vehicle and ExitIntersectionEvent is a non-static inner class of Vehicle. This didn't work, so we solved the problem by moving to a static inner class, as you can see in the code posted on Dec. 1.

    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.

  2. Background: In the discussion of the concept of a hierarchy of virtual machines in the Dec. 3 lecture, it was mentioned that our road-network framework could have been divided into a hierarchy, where the top level classes in the road network were general purpose, applicable to any computation on a road network from finding the shortest path for a GPS navigation application to simulation of a road network, as we have done.

    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).

  3. Background: In Lecture 25 on Dec. 1, it was asserted that no method needs more than one parameter. In fact, following the same methodology, we can eliminate all parameters and make all methods return void. Consider the following example, based on the first code given after the heading No method needs more than one parameter:
    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)

  4. A short question: Why is a process-oriented view of simulation a poor way to think about a logic simulator? (0.5 points)

  5. Background: In the final version of the logic simulator, Gates such as and and or had inputs of the form a in1 and a in2, which made good sense, but other types of gates, not and out were more awkward, since with just one input, connecting a wire to b in seems verbose.

    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)