Page 315 - Introduction to Programming with Java: A Problem Solving Approach
P. 315

                7.10 Problem Solving with Multiple Driven Classes 281
   Switch
   +NORMALLY_OPEN : boolean +use : String
-control : Controller
   +Switch(normallyOpen : boolean, control : Controller, use : String) +hit() : void
    /*********************************************************************
*
Switch.java
Dean & Dean
This class models switches.
*********************************************************************/
*
*
*
import java.util.Scanner;
public class Switch
{
}
// end class Switch
public final boolean NORMALLY_OPEN;
public String use;
// hit makes connection
// role in the system
       Apago PDF Enhancer
//******************************************************************
public Switch(
boolean normallyOpen, Controller control, String use)
this.NORMALLY_OPEN = normallyOpen;
this.control = control;
this.use = use;
// end constructor
//******************************************************************
private Controller control;
{
}
public void hit()
{
System.out.print(this.use + " switch hit. ");
control.actionEvent();
} // end hit
Figure 7.24
Switch class for the Garage Door program
Now, we’re ready for the GarageDoorSystem class, shown in Figures 7.25a and 7.25b. In Figure 7.25a, we declare an instance variable called state. Then we declare the four reference variables that refer to the
























































   313   314   315   316   317