LogicGates/eu.heili/AndGate.java

21 lines
490 B
Java
Raw Normal View History

2020-04-13 09:23:57 +00:00
public class AndGate extends LogicGate {
2020-04-13 09:14:15 +00:00
public AndGate(int inputnr) {
super(inputnr);
2020-04-13 09:23:57 +00:00
if (inputnr > 8)
throw (new TooManyInputsException());
2020-04-13 09:14:15 +00:00
}
2020-04-13 09:23:57 +00:00
public AndGate(boolean... inputvals) {
2020-04-13 09:14:15 +00:00
super(inputvals);
}
@Override
public boolean getOutput() {
boolean state = getInput(0).getValue();
2020-04-13 09:23:57 +00:00
for (int i = 1; i < getInputNumber(); i++) {
2020-04-13 09:14:15 +00:00
state &= getInput(i).getValue();
}
return state;
}
}