JAVA: Suppose we name the new class PrintEvent, with the static method initPrint
ID: 3828100 • Letter: J
Question
JAVA: Suppose we name the new class PrintEvent, with the static method initPrint local to PrintEvent. This architectural change has consequences.
a) What variable or variables pose difficulties?
b) In light of part a, what are the parameters to initPrint?
c) In light of parts a and b, what private static variables should be in class PrintEvent? (These may replace or supplement existing variables.)
output headline for logic output param i the interval between successive outputs public static void initPrint float i Simulation. schedule( new PrintEvent 0.0 f, i for Gate g gates System.out. print name System.out.println Output print event private static final class PrintEvent extends Simulation. Event private final float printInterval; Construct a print event eparam time the time at which to print aparam i the interval between print events public PrintEvent float time, float i super time print Interval i Every event must provide a trigger method public void trigger for Gate gr gates System.out.print g.printvalue System. out.println Simulation. schedule new PrintEvent time print interval, print IntervalExplanation / Answer
Answer :
a) Variables that pose difficulties
Variable 'i' can have difficulties.
b) What are the parameters to initPrint
Line : public static void initPrint( float i )
When you observe the above line you can know that the parameter for initPrint is "i"
Where 'i' = the interval between successive outputs
c) What private variables should be in class PrintEvent
Variable 'i' should be class "PrintEvent" because the context of value "i" is different in both "initPrint" and "PrintEvent"
If we don't make the variable 'i' private we can easily overwrite the data.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.