Commit e0205b46ea43868be31df8bb941d53264f542104
1 parent
0498df6f
fini
Showing
14 changed files
with
65 additions
and
63 deletions
Show diff stats
And.class
No preview for this file type
And.java
... | ... | @@ -5,15 +5,15 @@ public class And extends Porte2Entrees{ |
5 | 5 | void display(){ |
6 | 6 | }*/ |
7 | 7 | /*public boolean getEtat() throws NonConnecteException { |
8 | - if ((in1 == null) || (in2 == null)) { | |
9 | - throw new NonConnecteException(); | |
8 | + if ((in1 == null) || (in2 == null)) { | |
9 | + throw new NonConnecteException(); | |
10 | 10 | } else { |
11 | 11 | s=(in1.getEtat() && in2.getEtat()); |
12 | - return s; | |
13 | - } | |
12 | + return s; | |
13 | + } | |
14 | 14 | }*/ |
15 | 15 | |
16 | 16 | public boolean eval()throws NonConnecteException { |
17 | - return (in1.getEtat() && in2.getEtat()); | |
17 | + return (in1.getEtat() & in2.getEtat()); | |
18 | 18 | } |
19 | 19 | } | ... | ... |
LazySonde.class
No preview for this file type
LazySonde.java
... | ... | @@ -12,16 +12,16 @@ public class LazySonde extends Sonde{ |
12 | 12 | str1=null; |
13 | 13 | } |
14 | 14 | public boolean getEtat() throws NonConnecteException{ |
15 | - System.out.println(" je suis lazy SONNNNDEE"); | |
15 | + //System.out.println(" je suis lazy SONNNNDEE"); | |
16 | 16 | Scanner sc = new Scanner(System.in); |
17 | - if (str1 == null) { | |
18 | - throw new NonConnecteException(); | |
17 | + if (str1 == null) { | |
18 | + throw new NonConnecteException(); | |
19 | 19 | } |
20 | 20 | else if(valsor!=null){return valsor;} |
21 | 21 | |
22 | 22 | else { |
23 | 23 | System.out.println(str1+ " de " + c1 + " ,true ou false ? " ); |
24 | - | |
24 | + | |
25 | 25 | if (sc.hasNextBoolean()) { |
26 | 26 | valsor = sc.nextBoolean(); |
27 | 27 | return valsor; |
... | ... | @@ -29,10 +29,10 @@ public class LazySonde extends Sonde{ |
29 | 29 | else { |
30 | 30 | System.out.println("Nous avons pas compris votre choix, la valeur par default est false !"); |
31 | 31 | return false; |
32 | - } | |
32 | + } | |
33 | 33 | } |
34 | 34 | } |
35 | - | |
35 | + | |
36 | 36 | public void reset(){ |
37 | 37 | valsor=null; |
38 | 38 | return ; | ... | ... |
Not.class
No preview for this file type
Not.java
... | ... | @@ -4,37 +4,37 @@ |
4 | 4 | */ |
5 | 5 | |
6 | 6 | public class Not extends Porte { |
7 | - | |
7 | + | |
8 | 8 | protected Composant in; |
9 | - | |
10 | - public void setIn(Composant comp) { | |
11 | - in = comp; | |
9 | + | |
10 | + public void setIn(Composant comp) { | |
11 | + in = comp; | |
12 | 12 | } |
13 | 13 | public void probe(SondesTable tableSondes){ |
14 | 14 | if(in instanceof Interrupteur){ |
15 | - System.out.println(tableSondes.getSonde((Interrupteur)in,in,in.getId())); | |
15 | + setIn(tableSondes.getSonde((Interrupteur)in,in,in.getId())); | |
16 | 16 | } |
17 | 17 | } |
18 | 18 | public String description(){ |
19 | 19 | return getId() + " ||in: "+ in.getId(); |
20 | 20 | } |
21 | 21 | |
22 | - | |
22 | + | |
23 | 23 | public boolean getEtat() throws NonConnecteException { |
24 | - | |
24 | + | |
25 | 25 | if (in == null) { |
26 | - | |
26 | + | |
27 | 27 | throw new NonConnecteException(); |
28 | - | |
28 | + | |
29 | 29 | } else { |
30 | - | |
30 | + | |
31 | 31 | return !in.getEtat(); |
32 | - | |
32 | + | |
33 | 33 | } |
34 | 34 | } |
35 | 35 | public void unprobe(SondesTable tableSondes){ |
36 | 36 | if(in instanceof LazySonde){ |
37 | - System.out.println(tableSondes.getInterrupteur((LazySonde)in)); | |
37 | + setIn(tableSondes.getInterrupteur((LazySonde)in)); | |
38 | 38 | } |
39 | 39 | } |
40 | 40 | } | ... | ... |
Or.class
No preview for this file type
Or.java
... | ... | @@ -6,16 +6,16 @@ public class Or extends Porte2Entrees{ |
6 | 6 | }*/ |
7 | 7 | |
8 | 8 | /*public boolean getEtat() throws NonConnecteException { |
9 | - if ((in1 == null) || (in2 == null)) { | |
10 | - throw new NonConnecteException(); | |
9 | + if ((in1 == null) || (in2 == null)) { | |
10 | + throw new NonConnecteException(); | |
11 | 11 | } else { |
12 | 12 | s=(in1.getEtat() || in2.getEtat()); |
13 | - return s; | |
14 | - } | |
13 | + return s; | |
14 | + } | |
15 | 15 | }*/ |
16 | 16 | |
17 | 17 | public boolean eval() throws NonConnecteException{ |
18 | - return (in1.getEtat() || in2.getEtat()); | |
18 | + return (in1.getEtat() | in2.getEtat()); | |
19 | 19 | } |
20 | - | |
20 | + | |
21 | 21 | } | ... | ... |
Porte2Entrees.class
No preview for this file type
Porte2Entrees.java
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | public abstract class Porte2Entrees extends Porte { |
4 | 4 | Composant in1,in2; |
5 | 5 | Boolean s; |
6 | - | |
6 | + | |
7 | 7 | void setIN1(Composant comp){in1= comp;} |
8 | 8 | void setIN2(Composant comp){in2= comp;} |
9 | 9 | |
... | ... | @@ -18,24 +18,24 @@ public abstract class Porte2Entrees extends Porte { |
18 | 18 | |
19 | 19 | public void probe(SondesTable tableSondes){ |
20 | 20 | if(in1 instanceof Interrupteur){ |
21 | - tableSondes.getSonde((Interrupteur)in1,in1,in1.getId()); | |
21 | + setIN1(tableSondes.getSonde((Interrupteur)in1,in1,in1.getId())); | |
22 | 22 | } |
23 | 23 | if(in2 instanceof Interrupteur){ |
24 | - tableSondes.getSonde((Interrupteur)in2,in2,in2.getId()); | |
24 | + setIN2(tableSondes.getSonde((Interrupteur)in2,in2,in2.getId())); | |
25 | 25 | } |
26 | 26 | } |
27 | 27 | public void unprobe(SondesTable tableSondes){ |
28 | 28 | if(in1 instanceof LazySonde){ |
29 | - tableSondes.getInterrupteur((LazySonde)in1); | |
29 | + setIN1(tableSondes.getInterrupteur((LazySonde)in1)); | |
30 | 30 | } |
31 | 31 | if(in2 instanceof LazySonde){ |
32 | - tableSondes.getInterrupteur((LazySonde)in2); | |
32 | + setIN2(tableSondes.getInterrupteur((LazySonde)in2)); | |
33 | 33 | } |
34 | 34 | } |
35 | - | |
35 | + | |
36 | 36 | /*public boolean getEtat() throws NonConnecteException { |
37 | - if ((this.in1 == null) || (this.in2 == null)) { | |
38 | - throw new NonConnecteException(); | |
37 | + if ((this.in1 == null) || (this.in2 == null)) { | |
38 | + throw new NonConnecteException(); | |
39 | 39 | } |
40 | 40 | else if(s==null) { |
41 | 41 | s=this.eval(); |
... | ... | @@ -44,11 +44,11 @@ public abstract class Porte2Entrees extends Porte { |
44 | 44 | else{ return s;} |
45 | 45 | }*/ |
46 | 46 | public boolean getEtat() throws NonConnecteException { |
47 | - if ((this.in1 == null) || (this.in2 == null)) { | |
48 | - throw new NonConnecteException(); | |
47 | + if ((this.in1 == null) || (this.in2 == null)) { | |
48 | + throw new NonConnecteException(); | |
49 | 49 | } |
50 | 50 | else { |
51 | 51 | return this.eval(); |
52 | 52 | } |
53 | - } | |
53 | + } | |
54 | 54 | } | ... | ... |
SondesTable.class
No preview for this file type
SondesTable.java
... | ... | @@ -4,13 +4,13 @@ public class SondesTable{ |
4 | 4 | Map<LazySonde,Interrupteur> sondetointerrupteur = new HashMap<LazySonde,Interrupteur>(); |
5 | 5 | Map<Interrupteur,LazySonde> interrupteurtosonde = new HashMap<Interrupteur,LazySonde>(); |
6 | 6 | |
7 | - | |
7 | + | |
8 | 8 | public Interrupteur getInterrupteur(LazySonde sonde){ |
9 | 9 | return sondetointerrupteur.get(sonde); |
10 | 10 | } |
11 | - | |
11 | + | |
12 | 12 | public LazySonde getSonde(Interrupteur interrupteur,Composant cible, String entree){ |
13 | - | |
13 | + | |
14 | 14 | if(interrupteurtosonde.containsKey(interrupteur)){ |
15 | 15 | return interrupteurtosonde.get(interrupteur) ; |
16 | 16 | } |
... | ... | @@ -18,7 +18,7 @@ public class SondesTable{ |
18 | 18 | LazySonde lz1= new LazySonde(cible,entree); |
19 | 19 | interrupteurtosonde.put(interrupteur,lz1); |
20 | 20 | sondetointerrupteur.put(lz1,interrupteur); |
21 | - return interrupteurtosonde.get(interrupteur) ; | |
21 | + return lz1 ; | |
22 | 22 | } |
23 | 23 | } |
24 | 24 | public void resetSondes(){ |
... | ... | @@ -34,5 +34,5 @@ public class SondesTable{ |
34 | 34 | return ; |
35 | 35 | } |
36 | 36 | |
37 | - | |
37 | + | |
38 | 38 | } | ... | ... |
TestCircuits.class
No preview for this file type
TestCircuits.java
... | ... | @@ -5,7 +5,7 @@ import java.util.Scanner; |
5 | 5 | */ |
6 | 6 | |
7 | 7 | public class TestCircuits { |
8 | - | |
8 | + | |
9 | 9 | public static void main(String[] args) { |
10 | 10 | //Construction |
11 | 11 | Composant tabcomp[]= new Composant[7] ; |
... | ... | @@ -23,33 +23,34 @@ public class TestCircuits { |
23 | 23 | tabcomp[4]=i2; |
24 | 24 | tabcomp[5]=i3; |
25 | 25 | tabcomp[6]=v1; |
26 | - | |
27 | 26 | |
28 | - | |
27 | + | |
28 | + | |
29 | 29 | //Connexions |
30 | - | |
30 | + | |
31 | 31 | ((Or)tabcomp[0]).setIN1(tabcomp[3]); |
32 | - | |
32 | + | |
33 | 33 | ((Or)tabcomp[0]).setIN2(tabcomp[4]); |
34 | 34 | ((Not)tabcomp[2]).setIn(tabcomp[5]); |
35 | 35 | ((And)tabcomp[1]).setIN1(tabcomp[0]); |
36 | 36 | ((And)tabcomp[1]).setIN2(tabcomp[2]); |
37 | 37 | ((Vanne)tabcomp[6]).setIn(tabcomp[1]); |
38 | - | |
38 | + | |
39 | 39 | c1.setIN1(new LazySonde(c1,"in1")); |
40 | - | |
40 | + | |
41 | 41 | Circuit cir = new Circuit("circ",tabcomp); |
42 | 42 | test(cir); |
43 | - | |
43 | + | |
44 | 44 | //Affichage |
45 | 45 | //c1.setIN1(new LazySonde(c1,"in1")); |
46 | - | |
46 | + | |
47 | 47 | |
48 | 48 | System.out.println("Au revoir!"); |
49 | 49 | } |
50 | 50 | |
51 | 51 | static void test(Circuit circ){ |
52 | - circ.unprobe(); | |
52 | + | |
53 | + circ.probe(); | |
53 | 54 | /*System.out.println("Nomenclature:"); |
54 | 55 | System.out.println(circ.nomenclature()); |
55 | 56 | System.out.println(); |
... | ... | @@ -64,16 +65,17 @@ public class TestCircuits { |
64 | 65 | System.out.println();*/ |
65 | 66 | System.out.println("trace:"); |
66 | 67 | circ.traceEtats(); |
67 | - | |
68 | + | |
68 | 69 | System.out.println(circ.getIns()); |
69 | 70 | System.out.println(circ.getOuts()); |
70 | - circ.probe(); | |
71 | + circ.unprobe(); | |
72 | + | |
71 | 73 | //circ.resetSondes(); |
72 | - | |
73 | - | |
74 | + | |
75 | + | |
74 | 76 | } |
75 | 77 | |
76 | - | |
78 | + | |
77 | 79 | static void printIds(Composant[] tabc){ |
78 | 80 | for(Composant r : tabc){ |
79 | 81 | System.out.println(r.getId()); |
... | ... | @@ -82,13 +84,13 @@ public class TestCircuits { |
82 | 84 | static void description(Composant[] tabc){ |
83 | 85 | for(Composant r : tabc){ |
84 | 86 | System.out.println(r.description()); |
85 | - } | |
87 | + } | |
86 | 88 | } |
87 | - | |
89 | + | |
88 | 90 | static void traceEtats(Composant[] tabc){ |
89 | 91 | for(Composant r : tabc){ |
90 | 92 | System.out.println( r.traceEtat() ); |
91 | - | |
93 | + | |
92 | 94 | } |
93 | 95 | } |
94 | 96 | } | ... | ... |