public class TestHalfAdder { public static void main(String[] args) { Wire a = new Wire(); Wire b = new Wire(); Wire sum = new Wire(); Wire cout = new Wire(); HalfAdder ha = new HalfAdder(); ha.addInput(a, 0); ha.addInput(b, 1); ha.addOutput(sum, 0); ha.addOutput(cout, 1); a.setValue(true); b.setValue(true); System.out.println("1 + 1 = " + (sum.getValue()?1:0)); System.out.println("cout = " + (cout.getValue()?1:0)); a.setValue(true); b.setValue(false); System.out.println("1 + 0 = " + (sum.getValue()?1:0)); System.out.println("cout = " + (cout.getValue()?1:0)); a.setValue(false); b.setValue(true); System.out.println("0 + 1 = " + (sum.getValue()?1:0)); System.out.println("cout = " + (cout.getValue()?1:0)); a.setValue(false); b.setValue(false); System.out.println("0 + 0 = " + (sum.getValue()?1:0)); System.out.println("cout = " + (cout.getValue()?1:0)); } /* 1 + 1 = 0 cout = 1 1 + 0 = 1 cout = 0 0 + 1 = 1 cout = 0 0 + 0 = 0 cout = 0 */ }