Assignment 3, due Sep 8

Part of the homework for CS:2820, Fall 2017
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Assignments are to be turned in on paper. On every assignment, write your name, course and section number at the top. Write your name as it appears in your university records! Use the section number for which you are registered! We will not do detective work to figure out who did what. Work must be legible. Homework is due on paper in discussion section, usually at the start except when the assignment indicates that time to work on the assignment will be provided in class. Exceptions will be made only by advance arrangement with your TA (excepting "acts of God" outside your control). Never push homework under someone's door!

  1. Background: In the lectures for this week, our description of a road network assumes that all roads into a particular intersection are interchangable. In fact, this is not true. Coming into the intersection of Iowa Avenue and Madison St. from Iowa Avenue, there are 3 lanes, a right-turn lane, a left turn lane, and a center lane that can turn either right or left. This means that the lane you enter the intersection on matters because it determines the choice of lanes you have when you exit the intersection.

    Thus, the file describing a road network must state not merely that road a leads to intersection b, it must state which incoming lane of that intersection it connects to. For example, we might say that road a leads to the eastbound right-turn lane of intersection b.

    Similarly, while and, or and exclusive or functions are symmetrical, other functions such as the and not function discussed in the previous homework are not. For such functions, we cannot just say that a wire connects to a gate, we must state which input to that gate it connects to. So we might say that wire a connects to the inverting input of gate b.

    A Problem: Suggest a syntactic notation allowing you to write the fact that a road leads from a specific outgoing lane of one intersection to a specific incoming lane of another (a similar notation could connect a specific output of one logic gate to a specific input another). (0.5 points)

  2. Background: Now consider the problem of representing, inside the computer, a connection from a road to or from a particular incoming connection to an intersection. There are numerous solutions! First consider going perhaps a bit overboard and having a separate object for each lane in and out of an interesection. Where we used to have just one intersection object, we how have a constellation of objects, one central one for the intersection itself, and one for each lane in and out of that intersection.

    A Problem: How would this change the definition of class Road. Concentrate on changes to the data, ignore changes in the methods. (0.5 points)

  3. Background: As mentioned above, there are many solutions. Now, consider trying to avoid creating multiple objects for each intersection. It is just one intersection, with an array of incoming lanes and an array of outgoing lanes. Each array is indexed by lane number. Incoming and outgoing lanes may have textual names, but once a connection is made from a road to an intersection, lane numbers are used.

    A Problem: How would this change the definition of class Road. Concentrate on changes to the data, ignore changes in the methods. (0.5 points)

  4. Background: Java Scanner objects have lots of methods associated with them.

    A Problem: List all of the Scanner methods that can be used to pick successive numeric values from the input stream. (0.7 points)

  5. Background: The notes for Lecture 6 suggest having a call to Errors.fatal() if there are extra arguments, but the code doesn't tell the user about the extra arguments it found. In contrast, the call to Errors.fatal() given for a file that can't be opened gives useful feedback.

    a) Suggest simple code for the error message for extra arguments that shows the first extra argument. (0.4 points)

    b) Briefly explain why part a above only asked for the first extra argument. (You might try working out the code you'd have to write if you wanted the message to show all the extra arguments, but do not turn in this code, just explain what about that code made it unappealing in this context.) (0.4 points)