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

25 lines
727 B
Java

public class ExorGate extends LogicGate {
public ExorGate(int inputnr) {
super(inputnr);
if (inputnr > 2)
throw (new TooManyInputsException());
}
public ExorGate(DigitalInput... inputvals) {
super(inputvals);
if (inputvals.length > 2)
throw (new TooManyInputsException());
}
@Override
public boolean getOutput() {
boolean first = getInput(0).getValue();
for (int i = 1; i < getInputNumber(); i++) {
if (getInput(i).getValue() != first)
return true; // if there is one change return true
first = getInput(i).getValue();
}
return false; // all values are the same...
}
}