Assignment 10, due Apr 14
Part of
the homework for CS:2820, Spring 2017
|
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!
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)
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)
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)