LogicGates/eu.heili/Main.java
lukas-heiligenbrunner 574c58f1c5 added nand not nor enxor exor gates
and two bsp from teacher.
2020-04-14 11:01:51 +02:00

80 lines
2.3 KiB
Java

public class Main {
public static void main(String[] args) {
// teacher example:
OrGate o1 = new OrGate(2);
AndGate a2 = new AndGate(2);
// Verbinde Eingang 0 mit dem Ausgang vom OR - Gate.
a2.getInput(0).setValue(o1);
// Setze Eingang 1 auf 1.
a2.getInput(1).setValue(0);
// Setze Eingang 0 auf 0.
o1.getInput(0).setValue(0);
// Setze Eingang 1 auf 1.
o1.getInput(1).setValue(0);
/** some definition tests with better syntax (; */
AndGate gt = new AndGate(
new DigitalInput(0),
new DigitalInput(true),
new DigitalInput(o1),
new DigitalInput('H')
);
LogicGate or = new AndGate(
new DigitalInput(0),
new DigitalInput(1)
);
System.out.println(or.getOutput());
LogicGate nor = new NandGate(
new DigitalInput(0),
new DigitalInput(1)
);
/** bsp 1 **/
boolean x = false;
boolean y = true;
LogicGate s = new OrGate(
new DigitalInput(new AndGate(
new DigitalInput(new NotGate(
new DigitalInput(x)
)),
new DigitalInput(y)
)),
new DigitalInput(new AndGate(
new DigitalInput(x),
new DigitalInput(new NotGate(
new DigitalInput(y)
))
))
);
LogicGate c = new AndGate(
new DigitalInput(x),
new DigitalInput(y)
);
System.out.println("Bsp1");
System.out.println("output of c: " + c.getOutput());
System.out.println("output of s: " + s.getOutput());
/** bsp. 2 **/
boolean xx = true;
boolean yy = false;
LogicGate ss = new ExorGate(
new DigitalInput(xx),
new DigitalInput(yy)
);
LogicGate cc = new AndGate(
new DigitalInput(xx),
new DigitalInput(yy)
);
System.out.println("Bsp2");
System.out.println("output of c: " + cc.getOutput());
System.out.println("output of s: " + ss.getOutput());
}
}