Assignment 10, due Apr 14

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

On every assignment, write your name and section number. Write your name as it appears on your university ID card! Use the section number as it appears in your current registration! We will not do detective work to figure out who did what. Homework is due on paper at the start of your discussion section. Exceptions will be made only by advance arrangement with your TA (excepting "acts of God"). Never push homework under someone's door!

  1. Background: In the code distributed with the assignment for MP5, the columns of simulation output will only be properly titled if the gate names are all exactly 5 characters long. The code that does the relevant printing is:
    System.out.print( " " + g.name );
    

    A problem: Write code to replace the above that pads shorter names to 5 characters and truncates longer names. This is a small exercise in Java string manipulation. Computational efficiency is not really important, as this code is only used once to compute the title line of the output. Hint: It can be done in one simple expression involving concatenation and substring operations. (1 point)

  2. Background: The output required for MP5 relies on a method in class Gate called printValue(). This returns a string giving the appropriate graphical representation of that gate's logic transitions since the last time it was called.

    a) What new instance variable must be added to class Gate to make it possible for printValue() to do its job. (0.5 points)

    b) Explain how a 2-dimensional array of strings can be used to do the bulk of the work done by printValue(). (0.5 points)

  3. Background: The output required for printValue() in MP5 only requires that it show the value at the instant of each tick of the "print interval clock." If an engineer hooks an oscilloscope to a real logic gate's output, the scope will show very brief changes. We can fake this up as follows:

    We could even generalize this to allow such things as:

    a) What additional instance variable or variables would you add to class Gate to allow something approximating this more complex output format? (0.5 points)

    a) Briefly describe how you would use the data from part a) to create the output desired. Do not give code! (0.5 points)