Assignment 3, due Feb 1
Part of
the homework for CS:2820, Spring 2019
|
Assignments are to be turned in on paper. On every assignment, write your name, course and section number at the top of each page. 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!
For the sake of this exercise, though, consider the problem of outputting all of the extra arguments, so that the program behaves as follows:
[HawkID@fastx?? ~]$ java MP1 this that MP1: Extra argument that MP1: Can't open this [HawkID@fastx?? ~]$ java MP1 this that and the other MP1: Extra arguments that and the other MP1: Can't open this
a) Explain how you would change the code in method main would change in order to output either "Extra argument" or "extra arguments" as illustrated above. Think before you write. Suggest the easiest solution. Note: Don't write detailed code for this, instead, write a brief description of the change you would make. (0.5 points)
b) Explain what you would have to do in order to make the call to Errors.warn print all of the arguments, not just the first, in the event that the message begins "extra arguments." Again, don't actually write the code, but instead, give a brief description of the code required. (0.5 points)
When you encounter a class with such a variety of constructors, it is quite likely that one of them is the basic constructor that directly builds the class instance, while the others are quite probably "convenience" constructors that do some preliminary work before they call the basic constructor or alternatively before they duplicate the code of the basic constructor.
a) Which of the above is probably the basic constructor for class Scanner? (0.5 points)
b) One of the above constructors does the most auxiliary work before calling the basic constructor. Write the code for that constructor, using a call to the basic constructor to finish the job. (0.5 points)
gate a 0.5 xor gate b 1.0 threshold 1 F gate c 0.7 threshold 2 T wire a 3.0 b c wire b 1.8 c a wire c 0.9 a
In the above, gates have names, here a, b and c, and time delays from input to output, here 0.5, 1.0 and 0.7. Gates also have types, here xor and threshold. Threshold gates have additional attributes, the number of inputs that must be true for the output to be asserted, and the value to assert. Thus, gate b will assert false on its output if at least one input is true, and true otherwise, while gate c will assert true if at least two inputs are true, and false otherwise.
Wires have an origin, a delay and one or more destinations. Thus, the first wire listed above goes from gate a to gates b and c with a delay of 3.0.
The delays for gates and wires must, of course, be non-negative.
a) Suppose a threshold gate has three inputs, how do you set the threshold and output so that it computes the boolean and of these inputs? (0.3 points)
b) Suppose a threshold gate has two inputs, how do you set the threshold and output so that it computes the boolean nor of these inputs? (0.3 points)
c) (0.4 points) Suppose the only gate types in our simulation are xor and threshold. For each xor gate, a logic simulator could check, before starting the simulation, that there are exactly two input connections to that gate. What sanity checks could the simulator perform for each threshold gate?