import java.util.ArrayList; import java.util.Arrays; public abstract class LogicGate { private final ArrayList inputs = new ArrayList<>(); /** * validate gate output. * @return validated output */ public abstract boolean getOutput(); public LogicGate(int inputnr) { for (int i = 0; i < inputnr; i++) { inputs.add(new DigitalInput()); // generate new objects for new inputs } } public LogicGate(boolean... inputvals) { for (boolean i:inputvals) { inputs.add(new DigitalInput(i)); } } public DigitalInput getInput(int nr) { if (nr >= getInputNumber()) throw (new InputOutOfBoundsException()); return inputs.get(nr); } public int getInputNumber() { return inputs.size(); } }