1
6 public class Gate {
7
8 private boolean value; private String operation; private Gate input1; private Gate input2;
13 public Gate(Gate input1, String operation, Gate input2) {
15 this.input1 = input1;
16 this.input2 = input2;
17 this.operation = operation;
18 }
19
20 public Gate(String operation, Gate input) {
22 this.input1 = input;
23 this.operation = operation;
24 }
25
26 public Gate() {
27 this.operation = ""; }
29
30 public boolean getValue() {
31 return value;
32 }
33
34 public void setValue(boolean value) {
35 this.value = value;
36 }
37
38 public void operate() {
40 if (! operation.equals("")) {
41
42 if (operation.equals("AND")) {
43 value = input1.getValue() && input2.getValue(); }
45 else if (operation.equals("OR")) {
46 value = input1.getValue() || input2.getValue(); }
48 else if (operation.equals("NOT")) { value = ! input1.getValue();
50 }
51 }
52 }
53
54 }
55