Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Background: The code distributed for MP6 is not the end of the story. Consider t

ID: 3827841 • Letter: B

Question

Background: The code distributed for MP6 is not the end of the story. Consider the code given in class TernaryLogic. This class contains several subclasses of Simulation. Event. It might make sense to crack Print and Print ent into a separate source file. It is easy enough to rip them out of Logic, but they need access to a variable or variables that are private to TernaryLogic. Print ent, with the static method initPrint local to Print Event This architectural change has consequences Suppose we name the new class a) What variable or variables pose difficulties? (0.3 point) b) In light of part a, what are the parameters to initPrint? (0.3 point) c) In light of parts a and b. what private static variables should be in class PrintEvent? (These may replace or supplement existing variables.) (0.4 point)

Explanation / Answer

public class TernaryLogic { // lists of roads and intersectins static final LinkedList wires = new LinkedList (); static final LinkedList gates = new LinkedList (); public static Gate findGate( String s ) { for ( Gate g: gates ) { if (g.name.equals( s )) return g; } return null; } public static void initializeTernary( Scanner sc ) { while (sc.hasNext()) { // until we hit the end of the file String command = ScanSupport.nextName( sc ); if ("gate".equals( command )) { Gate g = Gate.newGate( sc ); if (g != null) gates.add( g ); } else if ("wire".equals( command )) { wires.add( new Wire( sc ) ); } else if ("".equals( command )) { // blank or comment // line holding -- ends up here! ScanSupport.lineEnd( sc, () -> "Line" ); } else { Errors.warn( "Command '" + command + "' is not gate or wire" ); sc.nextLine(); // skip the rest of the error } } } public static void checkNetwork() { for ( Gate g: gates ) { g.check(); } } public static void writeTernary() { for ( Gate g: gates ) { System.out.println( g.toString() ); } for ( Wire w: wires ) { System.out.println( w.toString() ); } } public static void initPrint( float i ) { Simulation.schedule( new PrintEvent( 0.0f, i ) ); for( Gate g: gates ) { System.out.print( " " + g.name ); } System.out.println(); } private static final class PrintEvent extends Simulation.Event { private final float printInterval; /** Construct a print event * @param time the time at which to print. * @param i the interval between print events. */ public PrintEvent( float time, float i ) { super( time ); printInterval = i; } /** Every event must provide a trigger method */ public void trigger() { for( Gate g: gates ) { System.out.print( " " + g.printValue() ); } System.out.println(); Simulation.schedule( new PrintEvent( time + printInterval, printInterval ) ); } } /** Terminate Simulation Event */ private static class ExitEvent extends Simulation.Event { public ExitEvent( float t ) { super( t ); } /** Every event must provide a trigger method */ public void trigger() { System.exit( 0 ); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote