1
6 public class FullAdder implements Component {
7
8 private Component[] comp = new Component[3];
10
11 private HalfAdder ha1;
13 private HalfAdder ha2;
14 private Gate or;
15
16 public FullAdder(Signal x, Signal y, Signal cIn) {
17
18 ha1 = new HalfAdder(x, y); ha2 = new HalfAdder(ha1.getSum(), cIn); or = new Or(ha1.getCarry(), ha2.getCarry());
23 comp[0] = ha1;
25 comp[1] = ha2;
26 comp[2] = or;
27 }
28
29 public void operate() {
31 for (int i=0; i<comp.length; i++)
32 comp[i].operate();
33 }
34
35 public Signal getSum() {
37 return ha2.getSum();
38 }
39
40 public Signal getCarryOut() {
42 return or.out();
43 }
44
45 }
46