added nand not nor enxor exor gates
and two bsp from teacher.
This commit is contained in:
		@@ -7,6 +7,8 @@ public class AndGate extends LogicGate {
 | 
			
		||||
 | 
			
		||||
    public AndGate(final DigitalInput... inputvals) {
 | 
			
		||||
        super(inputvals);
 | 
			
		||||
        if (inputvals.length > 8)
 | 
			
		||||
            throw (new TooManyInputsException());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -1,2 +1,14 @@
 | 
			
		||||
public class EnxorGate {
 | 
			
		||||
public class EnxorGate extends ExorGate{
 | 
			
		||||
    public EnxorGate(int inputnr) {
 | 
			
		||||
        super(inputnr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public EnxorGate(DigitalInput... inputvals) {
 | 
			
		||||
        super(inputvals);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean getOutput() {
 | 
			
		||||
        return !super.getOutput();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,2 +1,24 @@
 | 
			
		||||
public class ExorGate {
 | 
			
		||||
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...
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
public class Main {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        System.out.println("bla");
 | 
			
		||||
 | 
			
		||||
        // teacher example:
 | 
			
		||||
        OrGate o1 = new OrGate(2);
 | 
			
		||||
        AndGate a2 = new AndGate(2);
 | 
			
		||||
        // Verbinde Eingang 0 mit dem Ausgang vom OR - Gate.
 | 
			
		||||
@@ -13,12 +12,69 @@ public class Main {
 | 
			
		||||
        // Setze Eingang 1 auf 1.
 | 
			
		||||
        o1.getInput(1).setValue(0);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /** some definition tests with better syntax (; */
 | 
			
		||||
        AndGate gt = new AndGate(
 | 
			
		||||
                new DigitalInput(false),
 | 
			
		||||
                new DigitalInput(0),
 | 
			
		||||
                new DigitalInput(true),
 | 
			
		||||
                new DigitalInput(o1),
 | 
			
		||||
                new DigitalInput('H'));
 | 
			
		||||
                new DigitalInput('H')
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        System.out.println(a2.getOutput());
 | 
			
		||||
        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());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								eu.heili/NandGate.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								eu.heili/NandGate.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
public class NandGate extends AndGate{
 | 
			
		||||
    public NandGate(int inputnr) {
 | 
			
		||||
        super(inputnr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public NandGate(DigitalInput... inputvals) {
 | 
			
		||||
        super(inputvals);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean getOutput() {
 | 
			
		||||
        return !super.getOutput();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,2 +1,14 @@
 | 
			
		||||
public class NorGate {
 | 
			
		||||
public class NorGate extends OrGate{
 | 
			
		||||
    public NorGate(int inputnr) {
 | 
			
		||||
        super(inputnr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public NorGate(DigitalInput... inputvals) {
 | 
			
		||||
        super(inputvals);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean getOutput() {
 | 
			
		||||
        return !super.getOutput();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,2 +1,14 @@
 | 
			
		||||
public class NotGate {
 | 
			
		||||
public class NotGate extends LogicGate{
 | 
			
		||||
    public NotGate() {
 | 
			
		||||
        super(1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public NotGate(DigitalInput inputval) {
 | 
			
		||||
        super(inputval);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean getOutput() {
 | 
			
		||||
        return !getInput(0).getValue();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,14 @@
 | 
			
		||||
public class OrGate extends LogicGate {
 | 
			
		||||
    public OrGate(final int inputnr) {
 | 
			
		||||
        super(inputnr);
 | 
			
		||||
        if (inputnr > 8)
 | 
			
		||||
            throw (new TooManyInputsException());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public OrGate(final DigitalInput... inputvals) {
 | 
			
		||||
        super(inputvals);
 | 
			
		||||
        if (inputvals.length > 8)
 | 
			
		||||
            throw (new TooManyInputsException());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user