Assignment 3, due Sep 8
Part of
the homework for CS:2820, Fall 2017
|
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)
There is no one solution to this problem, but consider the following example notations as reasonable solutions for describing a road from lane y of intersection x to lane w of intersection z:
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)
Given that an intersection now has lane objects corresponding to each lane in or out of that intersection, roads now link lanes to lanes, and we leave it to each lane object to determine what intersection it is part of. So, class Road will now look something like this:
class Road { float travelTime; //measured in seconds Lane destination; //where the road goes Lane source; //where the comes from ... }
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)
Where we used to just refer to an intersection, we must now refer to an intersection and the array index.
class Road { float travelTime; //measured in seconds Intersection destination; //where the road goes int dstlane; //lane number of the destination Intersection source; //where the comes from int srctlane; //lane number of the source ... }
A Problem: List all of the Scanner methods that can be used to pick successive numeric values from the input stream. (0.7 points)
a) Suggest simple code for the error message for extra arguments that shows the first extra argument. (0.4 points)
Errors.fatal( "Unexpected extra argument: " + args[1] );
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)
It is very easy, knowing that there is at least one extra argument, to get the text of that argument. The code to print all of the extra arguments, in contrast, would involve a for loop to concatenate the successive extra arguments into a temporary variable before concatenating this with the error message text. Given that this is only an error message where the extra information is of little value to the user, this is not worth the effort.