1
5 public class HalfAdder {
6 public static void main(String[] args) {
7
8 Gate x = new Gate();
10 Gate y = new Gate();
11
12 Gate not1 = new Gate("NOT", x); Gate not2 = new Gate("NOT", y); Gate and1 = new Gate(not1, "AND", y); Gate and2 = new Gate(x, "AND", not2); Gate or = new Gate(and1, "OR", and2); Gate and3 = new Gate(x, "AND", y);
20 x.setValue(true);
22 y.setValue(false);
23
24 not1.operate();
26 not2.operate();
27 and1.operate();
28 and2.operate();
29 or.operate();
30 and3.operate();
31
32 boolean s = or.getValue(); boolean c = and3.getValue();
36 System.out.println("sum = " + s);
37 System.out.println("carry = " + c);
38
39 }
40
41 }
42