/Users/lyon/j4p/src/bookExamples/ch13Threads/fsm/ToggleFF.java

1    /** 
2     * Created by IntelliJ IDEA. 
3     * User: dlyon 
4     * Date: Feb 4, 2004 
5     * Time: 4:15:33 PM 
6     * To change this template use Options | File Templates. 
7     */ 
8    package bookExamples.ch13Threads.fsm; 
9     
10    
11   public class ToggleFF implements FSM { 
12       // Q+ = q't + t'q 
13       private boolean q = false; 
14    
15       public String toString() { 
16           return "" + q; 
17       } 
18    
19       public boolean[] f(boolean input[]) { 
20           boolean t = input[0]; 
21           q = (!q) && t || q && (!t); 
22           boolean b[] = new boolean[1]; 
23           b[0] = q; 
24           return b; 
25       } 
26    
27       public static void main(String args[]) { 
28           ToggleFF tt = new ToggleFF(); 
29           System.out.println(tt); 
30           for (int i = 0; i < 10; i++) { 
31               boolean input [] = {true}; 
32               tt.f(input); 
33               System.out.println(tt); 
34           } 
35       } 
36   } 
37