Commit 0498df6f091d6c0a99fe957739e7795fd3a2d22d
0 parents
first commit
Showing
45 changed files
with
1197 additions
and
0 deletions
Show diff stats
1 | +++ a/#Not.java# | ||
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +/** | ||
2 | + * | ||
3 | + * @author Bernard.Carre@polytech-lille.fr | ||
4 | + */ | ||
5 | + | ||
6 | +public class Not extends Porte { | ||
7 | + //... | ||
8 | + protected Composant in; | ||
9 | + | ||
10 | + public void setIn(Composant comp) { | ||
11 | + in = comp; | ||
12 | + } | ||
13 | + public void probe(SondesTable tableSondes){ | ||
14 | + if(in instanceof Interrupteur){ | ||
15 | + getSonde(in,in, | ||
16 | + } | ||
17 | + } | ||
18 | + public String description(){ | ||
19 | + return getId() + " ||in: "+ in.getId(); | ||
20 | + } | ||
21 | + | ||
22 | + | ||
23 | + public boolean getEtat() throws NonConnecteException { | ||
24 | + | ||
25 | + if (in == null) { | ||
26 | + | ||
27 | + throw new NonConnecteException(); | ||
28 | + | ||
29 | + } else { | ||
30 | + | ||
31 | + return !in.getEtat(); | ||
32 | + | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | +} |
1 | +++ a/#Porte2Entrees.java# | ||
@@ -0,0 +1,53 @@ | @@ -0,0 +1,53 @@ | ||
1 | + | ||
2 | + | ||
3 | +public abstract class Porte2Entrees extends Porte { | ||
4 | + Composant in1,in2; | ||
5 | + Boolean s; | ||
6 | + | ||
7 | + void setIN1(Composant comp){in1= comp;} | ||
8 | + void setIN2(Composant comp){in2= comp;} | ||
9 | + | ||
10 | + public String description(){ | ||
11 | + String s1 ="non connecté"; | ||
12 | + String s2 ="non connecté"; | ||
13 | + if(in1!=null){s1=in1.getId();} | ||
14 | + if(in2!=null){s2=in2.getId();} | ||
15 | + return getId() +" ||in1: " + s1 +" ||in2: "+ s2; | ||
16 | + } | ||
17 | + public abstract boolean eval()throws NonConnecteException; | ||
18 | + | ||
19 | + public void probe(SondesTable tableSondes){ | ||
20 | + if(in1 instanceof Interrupteur){ | ||
21 | + tableSondes.getSonde((Interrupteur)in1,in1,in1.getId()); | ||
22 | + } | ||
23 | + if(in2 instanceof Interrupteur){ | ||
24 | + tableSondes.getSonde((Interrupteur)in2,in2,in2.getId()); | ||
25 | + } | ||
26 | + } | ||
27 | + public void unprobe(SondesTable tableSondes){ | ||
28 | + if(in1 instanceof LazySonde){ | ||
29 | + tableSondes.getInterrupteur((LazySonde)in1); | ||
30 | + } | ||
31 | + if(in2 instanceof LazySonde){ | ||
32 | + tableSondes.getInterrupteur((LazySonde)in2); | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | + /*public boolean getEtat() throws NonConnecteException { | ||
37 | + if ((this.in1 == null) || (this.in2 == null)) { | ||
38 | + throw new NonConnecteException(); | ||
39 | + } | ||
40 | + else if(s==null) { | ||
41 | + s=this.eval(); | ||
42 | + return s; | ||
43 | + } | ||
44 | + else{ return s;} | ||
45 | + }*/ | ||
46 | + public boolean getEtat() throws NonConnecteException { | ||
47 | + if ((this.in1 == null) || (this.in2 == null)) { | ||
48 | + throw new NonConnecteException(); | ||
49 | + } | ||
50 | + else { | ||
51 | + return this.eval(); | ||
52 | + } | ||
53 | +} |
No preview for this file type
1 | +++ a/And.java | ||
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +public class And extends Porte2Entrees{ | ||
2 | + /*void run(){ | ||
3 | + s=in1 && in2; | ||
4 | + } | ||
5 | + void display(){ | ||
6 | + }*/ | ||
7 | + /*public boolean getEtat() throws NonConnecteException { | ||
8 | + if ((in1 == null) || (in2 == null)) { | ||
9 | + throw new NonConnecteException(); | ||
10 | + } else { | ||
11 | + s=(in1.getEtat() && in2.getEtat()); | ||
12 | + return s; | ||
13 | + } | ||
14 | + }*/ | ||
15 | + | ||
16 | + public boolean eval()throws NonConnecteException { | ||
17 | + return (in1.getEtat() && in2.getEtat()); | ||
18 | + } | ||
19 | +} |
1 | +++ a/And.java~ | ||
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +public class And extends Porte2Entrees{ | ||
2 | + /*void run(){ | ||
3 | + s=in1 && in2; | ||
4 | + } | ||
5 | + void display(){ | ||
6 | + }*/ | ||
7 | + /*public boolean getEtat() throws NonConnecteException { | ||
8 | + if ((in1 == null) || (in2 == null)) { | ||
9 | + throw new NonConnecteException(); | ||
10 | + } else { | ||
11 | + s=(in1.getEtat() && in2.getEtat()); | ||
12 | + return s; | ||
13 | + } | ||
14 | + }*/ | ||
15 | + | ||
16 | + public boolean eval(){ | ||
17 | + if ((in1 == null) || (in2 == null)) { | ||
18 | + throw new NonConnecteException(); | ||
19 | + } else { | ||
20 | + s=(in1.getEtat() && in2.getEtat()); | ||
21 | + return s; | ||
22 | + } | ||
23 | + } | ||
24 | +} |
No preview for this file type
1 | +++ a/Circuit.java | ||
@@ -0,0 +1,70 @@ | @@ -0,0 +1,70 @@ | ||
1 | +import java.util.* ; | ||
2 | + | ||
3 | +public class Circuit { | ||
4 | + String Nom; | ||
5 | + java.util.List<Composant> composants = new ArrayList<Composant>(); | ||
6 | + | ||
7 | + protected SondesTable tableSondes = new SondesTable(); | ||
8 | + | ||
9 | + public void traceEtats(){ | ||
10 | + System.out.println(Nom ); | ||
11 | + for(Composant r : composants){ | ||
12 | + System.out.println( r.traceEtat() ); | ||
13 | + } | ||
14 | + } | ||
15 | + | ||
16 | + | ||
17 | + public List<String> nomenclature(){ | ||
18 | + java.util.List<String> res= new ArrayList<String>(); | ||
19 | + for(Composant r : composants){ | ||
20 | + res.add(r.getId()); | ||
21 | + } | ||
22 | + return res; | ||
23 | + } | ||
24 | + | ||
25 | + public List<Interrupteur> getIns(){ | ||
26 | + java.util.List<Interrupteur> res = new ArrayList<Interrupteur>(); | ||
27 | + for(Composant r : composants){ | ||
28 | + if(r instanceof Interrupteur){res.add((Interrupteur)r);} | ||
29 | + } | ||
30 | + return res; | ||
31 | + } | ||
32 | + public void description(){ | ||
33 | + System.out.println(Nom ); | ||
34 | + for(Composant r : composants){ | ||
35 | + System.out.println( r.description() ); | ||
36 | + } | ||
37 | + } | ||
38 | + | ||
39 | + public List<Vanne> getOuts(){ | ||
40 | + java.util.List<Vanne> res = new ArrayList<Vanne>(); | ||
41 | + for(Composant r : composants){ | ||
42 | + if(r instanceof Vanne){res.add((Vanne)r);} | ||
43 | + } | ||
44 | + return res; | ||
45 | + } | ||
46 | + | ||
47 | + public Circuit(String nom, Composant[] cps){ | ||
48 | + Nom=nom; | ||
49 | + composants.addAll(Arrays.asList(cps)); | ||
50 | + Collections.sort(composants); | ||
51 | + } | ||
52 | + | ||
53 | + public void probe(){ | ||
54 | + for(Composant c : composants){ | ||
55 | + if(c instanceof Porte){ ((Porte)c).probe(tableSondes);} | ||
56 | + } | ||
57 | + } | ||
58 | + public void resetSondes(){ | ||
59 | + tableSondes.resetSondes(); | ||
60 | + } | ||
61 | + public void unprobe(){ | ||
62 | + for(Composant c : composants){ | ||
63 | + if(c instanceof Porte){((Porte)c).unprobe(tableSondes);} | ||
64 | + } | ||
65 | + } | ||
66 | + | ||
67 | + | ||
68 | + | ||
69 | + | ||
70 | +} |
1 | +++ a/Circuit.java~ | ||
@@ -0,0 +1,70 @@ | @@ -0,0 +1,70 @@ | ||
1 | +import java.util.* ; | ||
2 | + | ||
3 | +public class Circuit { | ||
4 | + String Nom; | ||
5 | + java.util.List<Composant> composants = new ArrayList<Composant>(); | ||
6 | + | ||
7 | + protected SondesTable tableSondes = new SondesTable(); | ||
8 | + | ||
9 | + public void traceEtats(){ | ||
10 | + System.out.println(Nom ); | ||
11 | + for(Composant r : composants){ | ||
12 | + System.out.println( r.traceEtat() ); | ||
13 | + } | ||
14 | + } | ||
15 | + | ||
16 | + | ||
17 | + public List<String> nomenclature(){ | ||
18 | + java.util.List<String> res= new ArrayList<String>(); | ||
19 | + for(Composant r : composants){ | ||
20 | + res.add(r.getId()); | ||
21 | + } | ||
22 | + return res; | ||
23 | + } | ||
24 | + | ||
25 | + public List<Interrupteur> getIns(){ | ||
26 | + java.util.List<Interrupteur> res = new ArrayList<Interrupteur>(); | ||
27 | + for(Composant r : composants){ | ||
28 | + if(r instanceof Interrupteur){res.add((Interrupteur)r);} | ||
29 | + } | ||
30 | + return res; | ||
31 | + } | ||
32 | + public void description(){ | ||
33 | + System.out.println(Nom ); | ||
34 | + for(Composant r : composants){ | ||
35 | + System.out.println( r.description() ); | ||
36 | + } | ||
37 | + } | ||
38 | + | ||
39 | + public List<Vanne> getOuts(){ | ||
40 | + java.util.List<Vanne> res = new ArrayList<Vanne>(); | ||
41 | + for(Composant r : composants){ | ||
42 | + if(r instanceof Vanne){res.add((Vanne)r);} | ||
43 | + } | ||
44 | + return res; | ||
45 | + } | ||
46 | + | ||
47 | + public Circuit(String nom, Composant[] cps){ | ||
48 | + Nom=nom; | ||
49 | + composants.addAll(Arrays.asList(cps)); | ||
50 | + Collections.sort(composants); | ||
51 | + } | ||
52 | + | ||
53 | + public void probe(){ | ||
54 | + for(Composant c : composants){ | ||
55 | + ((Porte)c).probe(tableSondes); | ||
56 | + } | ||
57 | + } | ||
58 | + public void resetSondes(){ | ||
59 | + tableSondes.resetSondes(); | ||
60 | + } | ||
61 | + public void unprobe(){ | ||
62 | + for(Composant c : composants){ | ||
63 | + ((Porte)c).unprobe(tableSondes); | ||
64 | + } | ||
65 | + } | ||
66 | + | ||
67 | + | ||
68 | + | ||
69 | + | ||
70 | +} |
No preview for this file type
1 | +++ a/Composant.java | ||
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +/** | ||
2 | + * | ||
3 | + * @author Bernard.Carre@polytech-lille.fr | ||
4 | + */ | ||
5 | + | ||
6 | +public abstract class Composant implements Comparable<Composant> { | ||
7 | + //... | ||
8 | + public String getId() { | ||
9 | + | ||
10 | + return super.toString(); // class@numero renvoye par Object | ||
11 | + | ||
12 | + } | ||
13 | + public abstract String description(); | ||
14 | + public abstract boolean getEtat() throws NonConnecteException; | ||
15 | + | ||
16 | + public String traceEtat(){ | ||
17 | + String s = this.description(); | ||
18 | + | ||
19 | + try{ | ||
20 | + s=s+" "+ this.getEtat(); | ||
21 | + }catch(NonConnecteException ex){ | ||
22 | + s=s+" non connecte"; | ||
23 | + } | ||
24 | + return s; | ||
25 | + } | ||
26 | + public int compareTo(Composant c) { | ||
27 | + return (this.getId()).compareTo(c.getId()); | ||
28 | + } | ||
29 | +} |
1 | +++ a/Composant.java~ | ||
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +/** | ||
2 | + * | ||
3 | + * @author Bernard.Carre@polytech-lille.fr | ||
4 | + */ | ||
5 | + | ||
6 | +public abstract class Composant implements Comparable<Composant> { | ||
7 | + //... | ||
8 | + public String getId() { | ||
9 | + | ||
10 | + return super.toString(); // class@numero renvoye par Object | ||
11 | + | ||
12 | + } | ||
13 | + public abstract String description(); | ||
14 | + public abstract boolean getEtat() throws NonConnecteException; | ||
15 | + public abstract void probe(); | ||
16 | + public String traceEtat(){ | ||
17 | + String s = this.description(); | ||
18 | + | ||
19 | + try{ | ||
20 | + s=s+" "+ this.getEtat(); | ||
21 | + }catch(NonConnecteException ex){ | ||
22 | + s=s+" non connecte"; | ||
23 | + } | ||
24 | + return s; | ||
25 | + } | ||
26 | + public int compareTo(Composant c) { | ||
27 | + return (this.getId()).compareTo(c.getId()); | ||
28 | + } | ||
29 | +} |
No preview for this file type
1 | +++ a/Interrupteur.java | ||
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +/** | ||
2 | + * | ||
3 | + * @author Bernard.Carre@polytech-lille.fr | ||
4 | + */ | ||
5 | + | ||
6 | + | ||
7 | +public class Interrupteur extends Composant { | ||
8 | + //... | ||
9 | + | ||
10 | + protected boolean etat; | ||
11 | + | ||
12 | + public void on() { | ||
13 | + | ||
14 | + etat = true; | ||
15 | + | ||
16 | + } | ||
17 | + | ||
18 | + public void off() { | ||
19 | + | ||
20 | + etat = false; | ||
21 | + | ||
22 | + } | ||
23 | + | ||
24 | + public boolean getEtat() throws NonConnecteException { | ||
25 | + | ||
26 | + return etat; | ||
27 | + | ||
28 | + } | ||
29 | + public String description(){ | ||
30 | + return getId(); | ||
31 | + } | ||
32 | + | ||
33 | +} |
1 | +++ a/Interrupteur.java~ | ||
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +/** | ||
2 | + * | ||
3 | + * @author Bernard.Carre@polytech-lille.fr | ||
4 | + */ | ||
5 | + | ||
6 | + | ||
7 | +public class Interrupteur extends Composant { | ||
8 | + //... | ||
9 | + | ||
10 | + protected boolean etat; | ||
11 | + | ||
12 | + public void on() { | ||
13 | + | ||
14 | + etat = true; | ||
15 | + | ||
16 | + } | ||
17 | + | ||
18 | + public void off() { | ||
19 | + | ||
20 | + etat = false; | ||
21 | + | ||
22 | + } | ||
23 | + | ||
24 | + public boolean getEtat() throws NonConnecteException { | ||
25 | + | ||
26 | + return etat; | ||
27 | + | ||
28 | + } | ||
29 | + public String description(){ | ||
30 | + return getId(); | ||
31 | + } | ||
32 | + | ||
33 | +} |
No preview for this file type
1 | +++ a/LazySonde.java | ||
@@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
1 | +import java.util.Scanner; | ||
2 | +public class LazySonde extends Sonde{ | ||
3 | + Boolean valsor; | ||
4 | + | ||
5 | + LazySonde(Composant c, String str){ | ||
6 | + c1=c; | ||
7 | + str1=str; | ||
8 | + } | ||
9 | + | ||
10 | + LazySonde(){ | ||
11 | + c1=null; | ||
12 | + str1=null; | ||
13 | + } | ||
14 | + public boolean getEtat() throws NonConnecteException{ | ||
15 | + System.out.println(" je suis lazy SONNNNDEE"); | ||
16 | + Scanner sc = new Scanner(System.in); | ||
17 | + if (str1 == null) { | ||
18 | + throw new NonConnecteException(); | ||
19 | + } | ||
20 | + else if(valsor!=null){return valsor;} | ||
21 | + | ||
22 | + else { | ||
23 | + System.out.println(str1+ " de " + c1 + " ,true ou false ? " ); | ||
24 | + | ||
25 | + if (sc.hasNextBoolean()) { | ||
26 | + valsor = sc.nextBoolean(); | ||
27 | + return valsor; | ||
28 | + } | ||
29 | + else { | ||
30 | + System.out.println("Nous avons pas compris votre choix, la valeur par default est false !"); | ||
31 | + return false; | ||
32 | + } | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | + public void reset(){ | ||
37 | + valsor=null; | ||
38 | + return ; | ||
39 | + } | ||
40 | +} |
1 | +++ a/LazySonde.java~ | ||
@@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
1 | +import java.util.Scanner; | ||
2 | +public class LazySonde extends Sonde{ | ||
3 | + Boolean valsor; | ||
4 | + | ||
5 | + LazySonde(Composant c, String str){ | ||
6 | + c1=c; | ||
7 | + str1=str; | ||
8 | + } | ||
9 | + | ||
10 | + LazySonde(){ | ||
11 | + c1=null; | ||
12 | + str1=null; | ||
13 | + } | ||
14 | + public boolean getEtat() throws NonConnecteException{ | ||
15 | + System.out.println(" je suis lazy SONNNNDEE"); | ||
16 | + Scanner sc = new Scanner(System.in); | ||
17 | + if (str1 == null) { | ||
18 | + throw new NonConnecteException(); | ||
19 | + } | ||
20 | + else if(valsor!=null){return valsor;} | ||
21 | + | ||
22 | + else { | ||
23 | + System.out.println(str1+ " de " + c1 + " ,true ou false ? " ); | ||
24 | + | ||
25 | + if (sc.hasNextBoolean()) { | ||
26 | + valsor = sc.nextBoolean(); | ||
27 | + return valsor; | ||
28 | + } | ||
29 | + else { | ||
30 | + System.out.println("Nous avons pas compris votre choix, la valeur par default est false !"); | ||
31 | + return false; | ||
32 | + } | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | + public void reset(){ | ||
37 | + this.valsor=null; | ||
38 | + return ; | ||
39 | + } | ||
40 | +} |
No preview for this file type
No preview for this file type
1 | +++ a/Not.java | ||
@@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
1 | +/** | ||
2 | + * | ||
3 | + * @author Bernard.Carre@polytech-lille.fr | ||
4 | + */ | ||
5 | + | ||
6 | +public class Not extends Porte { | ||
7 | + | ||
8 | + protected Composant in; | ||
9 | + | ||
10 | + public void setIn(Composant comp) { | ||
11 | + in = comp; | ||
12 | + } | ||
13 | + public void probe(SondesTable tableSondes){ | ||
14 | + if(in instanceof Interrupteur){ | ||
15 | + System.out.println(tableSondes.getSonde((Interrupteur)in,in,in.getId())); | ||
16 | + } | ||
17 | + } | ||
18 | + public String description(){ | ||
19 | + return getId() + " ||in: "+ in.getId(); | ||
20 | + } | ||
21 | + | ||
22 | + | ||
23 | + public boolean getEtat() throws NonConnecteException { | ||
24 | + | ||
25 | + if (in == null) { | ||
26 | + | ||
27 | + throw new NonConnecteException(); | ||
28 | + | ||
29 | + } else { | ||
30 | + | ||
31 | + return !in.getEtat(); | ||
32 | + | ||
33 | + } | ||
34 | + } | ||
35 | + public void unprobe(SondesTable tableSondes){ | ||
36 | + if(in instanceof LazySonde){ | ||
37 | + System.out.println(tableSondes.getInterrupteur((LazySonde)in)); | ||
38 | + } | ||
39 | + } | ||
40 | +} |
1 | +++ a/Not.java~ | ||
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +/** | ||
2 | + * | ||
3 | + * @author Bernard.Carre@polytech-lille.fr | ||
4 | + */ | ||
5 | + | ||
6 | +public class Not extends Porte { | ||
7 | + //... | ||
8 | + protected Composant in; | ||
9 | + | ||
10 | + public void setIn(Composant comp) { | ||
11 | + in = comp; | ||
12 | + } | ||
13 | + public void probe(SondesTable tableSondes){ | ||
14 | + if(in instanceof Interrupteur){ | ||
15 | + tableSondes.getSonde((Interrupteur)in,in,in.getId()); | ||
16 | + } | ||
17 | + } | ||
18 | + public String description(){ | ||
19 | + return getId() + " ||in: "+ in.getId(); | ||
20 | + } | ||
21 | + | ||
22 | + | ||
23 | + public boolean getEtat() throws NonConnecteException { | ||
24 | + | ||
25 | + if (in == null) { | ||
26 | + | ||
27 | + throw new NonConnecteException(); | ||
28 | + | ||
29 | + } else { | ||
30 | + | ||
31 | + return !in.getEtat(); | ||
32 | + | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | +} |
No preview for this file type
1 | +++ a/Or.java | ||
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +public class Or extends Porte2Entrees{ | ||
2 | + /* void run(){ | ||
3 | + s=in1 || in2; | ||
4 | + } | ||
5 | + void display(){ | ||
6 | + }*/ | ||
7 | + | ||
8 | + /*public boolean getEtat() throws NonConnecteException { | ||
9 | + if ((in1 == null) || (in2 == null)) { | ||
10 | + throw new NonConnecteException(); | ||
11 | + } else { | ||
12 | + s=(in1.getEtat() || in2.getEtat()); | ||
13 | + return s; | ||
14 | + } | ||
15 | + }*/ | ||
16 | + | ||
17 | + public boolean eval() throws NonConnecteException{ | ||
18 | + return (in1.getEtat() || in2.getEtat()); | ||
19 | + } | ||
20 | + | ||
21 | +} |
1 | +++ a/Or.java~ | ||
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +public class Or extends Porte2Entrees{ | ||
2 | + /* void run(){ | ||
3 | + s=in1 || in2; | ||
4 | + } | ||
5 | + void display(){ | ||
6 | + }*/ | ||
7 | + | ||
8 | + /*public boolean getEtat() throws NonConnecteException { | ||
9 | + if ((in1 == null) || (in2 == null)) { | ||
10 | + throw new NonConnecteException(); | ||
11 | + } else { | ||
12 | + s=(in1.getEtat() || in2.getEtat()); | ||
13 | + return s; | ||
14 | + } | ||
15 | + }*/ | ||
16 | + | ||
17 | + public boolean eval(){ | ||
18 | + if ((in1 == null) || (in2 == null)) { | ||
19 | + throw new NonConnecteException(); | ||
20 | + } else { | ||
21 | + s=(in1.getEtat() || in2.getEtat()); | ||
22 | + return s; | ||
23 | + } | ||
24 | + } | ||
25 | + | ||
26 | +} |
No preview for this file type
No preview for this file type
1 | +++ a/Porte2Entrees.java | ||
@@ -0,0 +1,54 @@ | @@ -0,0 +1,54 @@ | ||
1 | + | ||
2 | + | ||
3 | +public abstract class Porte2Entrees extends Porte { | ||
4 | + Composant in1,in2; | ||
5 | + Boolean s; | ||
6 | + | ||
7 | + void setIN1(Composant comp){in1= comp;} | ||
8 | + void setIN2(Composant comp){in2= comp;} | ||
9 | + | ||
10 | + public String description(){ | ||
11 | + String s1 ="non connecté"; | ||
12 | + String s2 ="non connecté"; | ||
13 | + if(in1!=null){s1=in1.getId();} | ||
14 | + if(in2!=null){s2=in2.getId();} | ||
15 | + return getId() +" ||in1: " + s1 +" ||in2: "+ s2; | ||
16 | + } | ||
17 | + public abstract boolean eval()throws NonConnecteException; | ||
18 | + | ||
19 | + public void probe(SondesTable tableSondes){ | ||
20 | + if(in1 instanceof Interrupteur){ | ||
21 | + tableSondes.getSonde((Interrupteur)in1,in1,in1.getId()); | ||
22 | + } | ||
23 | + if(in2 instanceof Interrupteur){ | ||
24 | + tableSondes.getSonde((Interrupteur)in2,in2,in2.getId()); | ||
25 | + } | ||
26 | + } | ||
27 | + public void unprobe(SondesTable tableSondes){ | ||
28 | + if(in1 instanceof LazySonde){ | ||
29 | + tableSondes.getInterrupteur((LazySonde)in1); | ||
30 | + } | ||
31 | + if(in2 instanceof LazySonde){ | ||
32 | + tableSondes.getInterrupteur((LazySonde)in2); | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | + /*public boolean getEtat() throws NonConnecteException { | ||
37 | + if ((this.in1 == null) || (this.in2 == null)) { | ||
38 | + throw new NonConnecteException(); | ||
39 | + } | ||
40 | + else if(s==null) { | ||
41 | + s=this.eval(); | ||
42 | + return s; | ||
43 | + } | ||
44 | + else{ return s;} | ||
45 | + }*/ | ||
46 | + public boolean getEtat() throws NonConnecteException { | ||
47 | + if ((this.in1 == null) || (this.in2 == null)) { | ||
48 | + throw new NonConnecteException(); | ||
49 | + } | ||
50 | + else { | ||
51 | + return this.eval(); | ||
52 | + } | ||
53 | + } | ||
54 | +} |
1 | +++ a/Porte2Entrees.java~ | ||
@@ -0,0 +1,54 @@ | @@ -0,0 +1,54 @@ | ||
1 | + | ||
2 | + | ||
3 | +public abstract class Porte2Entrees extends Porte { | ||
4 | + Composant in1,in2; | ||
5 | + Boolean s; | ||
6 | + | ||
7 | + void setIN1(Composant comp){in1= comp;} | ||
8 | + void setIN2(Composant comp){in2= comp;} | ||
9 | + | ||
10 | + public String description(){ | ||
11 | + String s1 ="non connecté"; | ||
12 | + String s2 ="non connecté"; | ||
13 | + if(in1!=null){s1=in1.getId();} | ||
14 | + if(in2!=null){s2=in2.getId();} | ||
15 | + return getId() +" ||in1: " + s1 +" ||in2: "+ s2; | ||
16 | + } | ||
17 | + public abstract boolean eval()throws NonConnecteException; | ||
18 | + | ||
19 | + public void probe(SondesTable tableSondes){ | ||
20 | + if(in1 instanceof Interrupteur){ | ||
21 | + tableSondes.getSonde((Interrupteur)in1,in1,in1.getId()); | ||
22 | + } | ||
23 | + if(in2 instanceof Interrupteur){ | ||
24 | + tableSondes.getSonde((Interrupteur)in2,in2,in2.getId()); | ||
25 | + } | ||
26 | + } | ||
27 | + public void unprobe(SondesTable tableSondes){ | ||
28 | + if(in1 instanceof Interrupteur){ | ||
29 | + tableSondes.getInterrupteur(in1); | ||
30 | + } | ||
31 | + if(in2 instanceof Interrupteur){ | ||
32 | + tableSondes.getInterrupteur(in2); | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | + /*public boolean getEtat() throws NonConnecteException { | ||
37 | + if ((this.in1 == null) || (this.in2 == null)) { | ||
38 | + throw new NonConnecteException(); | ||
39 | + } | ||
40 | + else if(s==null) { | ||
41 | + s=this.eval(); | ||
42 | + return s; | ||
43 | + } | ||
44 | + else{ return s;} | ||
45 | + }*/ | ||
46 | + public boolean getEtat() throws NonConnecteException { | ||
47 | + if ((this.in1 == null) || (this.in2 == null)) { | ||
48 | + throw new NonConnecteException(); | ||
49 | + } | ||
50 | + else { | ||
51 | + return this.eval(); | ||
52 | + } | ||
53 | + } | ||
54 | +} |
No preview for this file type
1 | +++ a/Sonde.java | ||
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +import java.util.Scanner; | ||
2 | +public abstract class Sonde extends Composant{ | ||
3 | + Composant c1; | ||
4 | + String str1; | ||
5 | + Sonde(Composant c, String str){ | ||
6 | + c1=c; | ||
7 | + str1=str; | ||
8 | + } | ||
9 | + | ||
10 | + Sonde(){ | ||
11 | + c1=null; | ||
12 | + str1=null; | ||
13 | + } | ||
14 | + public abstract boolean getEtat() throws NonConnecteException; | ||
15 | + | ||
16 | + public String description(){ | ||
17 | + return c1 + str1 ; | ||
18 | + } | ||
19 | +} |
1 | +++ a/Sonde.java~ | ||
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +import java.util.Scanner; | ||
2 | +public abstract class Sonde extends Composant{ | ||
3 | + Composant c1; | ||
4 | + String str1; | ||
5 | + Sonde(Composant c, String str){ | ||
6 | + c1=c; | ||
7 | + str1=str; | ||
8 | + } | ||
9 | + | ||
10 | + Sonde(){ | ||
11 | + c1=null; | ||
12 | + str1=null; | ||
13 | + } | ||
14 | + public abstract boolean getEtat() throws NonConnecteException; | ||
15 | + /*public boolean getEtat() throws NonConnecteException{ | ||
16 | + Scanner sc = new Scanner(System.in); | ||
17 | + if (str1 == null) { | ||
18 | + throw new NonConnecteException(); | ||
19 | + } else { | ||
20 | + System.out.println(str1+ " de " + c1 + " ,true ou false ? " ); | ||
21 | + | ||
22 | + if (sc.hasNextBoolean()) { | ||
23 | + boolean str = sc.nextBoolean(); | ||
24 | + return str; | ||
25 | + } | ||
26 | + else { | ||
27 | + System.out.println("Nous avons pas compris votre choix, la valeur par default est false !"); | ||
28 | + return false; | ||
29 | + } | ||
30 | + } | ||
31 | + }*/ | ||
32 | + | ||
33 | + public String description(){ | ||
34 | + return c1 + str1 ; | ||
35 | + } | ||
36 | +} |
No preview for this file type
1 | +++ a/SondesTable.java | ||
@@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
1 | +import java.util.* ; | ||
2 | + | ||
3 | +public class SondesTable{ | ||
4 | + Map<LazySonde,Interrupteur> sondetointerrupteur = new HashMap<LazySonde,Interrupteur>(); | ||
5 | + Map<Interrupteur,LazySonde> interrupteurtosonde = new HashMap<Interrupteur,LazySonde>(); | ||
6 | + | ||
7 | + | ||
8 | + public Interrupteur getInterrupteur(LazySonde sonde){ | ||
9 | + return sondetointerrupteur.get(sonde); | ||
10 | + } | ||
11 | + | ||
12 | + public LazySonde getSonde(Interrupteur interrupteur,Composant cible, String entree){ | ||
13 | + | ||
14 | + if(interrupteurtosonde.containsKey(interrupteur)){ | ||
15 | + return interrupteurtosonde.get(interrupteur) ; | ||
16 | + } | ||
17 | + else{ | ||
18 | + LazySonde lz1= new LazySonde(cible,entree); | ||
19 | + interrupteurtosonde.put(interrupteur,lz1); | ||
20 | + sondetointerrupteur.put(lz1,interrupteur); | ||
21 | + return interrupteurtosonde.get(interrupteur) ; | ||
22 | + } | ||
23 | + } | ||
24 | + public void resetSondes(){ | ||
25 | + for( LazySonde e :interrupteurtosonde.values()){ | ||
26 | + e.reset(); | ||
27 | + } | ||
28 | + | ||
29 | + return ; | ||
30 | + } | ||
31 | + public void clear(){ | ||
32 | + sondetointerrupteur.clear(); | ||
33 | + interrupteurtosonde.clear(); | ||
34 | + return ; | ||
35 | + } | ||
36 | + | ||
37 | + | ||
38 | +} |
1 | +++ a/SondesTable.java~ | ||
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +import java.util.* ; | ||
2 | + | ||
3 | +public class SondesTable{ | ||
4 | + Map< Sonde,Interrupteur> sondetointerrupteur = new HashMap< Sonde,Interrupteur>(); | ||
5 | + Map<Interrupteur,Sonde> interrupteurtosonde = new HashMap<Interrupteur,Sonde>(); | ||
6 | + | ||
7 | + | ||
8 | + public Interrupteur getInterrupteur(LazySonde sonde){ | ||
9 | + return sondetointerrupteur.get(sonde); | ||
10 | + | ||
11 | + | ||
12 | + } | ||
13 | + | ||
14 | + public LazySonde getSonde(Interrupteur interrupteur,Composant cible, String entree){ | ||
15 | + return ; | ||
16 | + } | ||
17 | + public void resetSondes(){ | ||
18 | + for( | ||
19 | + return ; | ||
20 | + } | ||
21 | + public void clear(){ | ||
22 | + return ; | ||
23 | + } | ||
24 | + | ||
25 | + | ||
26 | +} |
1 | +++ a/TESTcircuit.txt | ||
@@ -0,0 +1,91 @@ | @@ -0,0 +1,91 @@ | ||
1 | +import java.util.Scanner; | ||
2 | +/** | ||
3 | + * | ||
4 | + * @author Bernard.Carre@polytech-lille.fr | ||
5 | + */ | ||
6 | + | ||
7 | +public class TestCircuits { | ||
8 | + | ||
9 | + public static void main(String[] args) { | ||
10 | + //Construction | ||
11 | + Composant tabcomp[]= new Composant[7] ; | ||
12 | + Or c1=new Or(); | ||
13 | + And c2= new And(); | ||
14 | + Not c3= new Not(); | ||
15 | + Interrupteur i1 = new Interrupteur(); | ||
16 | + Interrupteur i2 = new Interrupteur(); | ||
17 | + Interrupteur i3 = new Interrupteur(); | ||
18 | + Vanne v1= new Vanne(); | ||
19 | + tabcomp[0]=c1; | ||
20 | + tabcomp[1]=c2; | ||
21 | + tabcomp[2]=c3; | ||
22 | + tabcomp[3]=i1; | ||
23 | + tabcomp[4]=i2; | ||
24 | + tabcomp[5]=i3; | ||
25 | + tabcomp[6]=v1; | ||
26 | + | ||
27 | + | ||
28 | + | ||
29 | + //Connexions | ||
30 | + | ||
31 | + //((Or)tabcomp[0]).setIN1(tabcomp[3]); | ||
32 | + | ||
33 | + ((Or)tabcomp[0]).setIN2(tabcomp[4]); | ||
34 | + ((Not)tabcomp[2]).setIn(tabcomp[5]); | ||
35 | + ((And)tabcomp[1]).setIN1(tabcomp[0]); | ||
36 | + ((And)tabcomp[1]).setIN2(tabcomp[2]); | ||
37 | + ((Vanne)tabcomp[6]).setIn(tabcomp[1]); | ||
38 | + | ||
39 | + //Affichage | ||
40 | + c1.setIN1(new LazySonde(c1,"in1")); | ||
41 | + | ||
42 | + //try{ | ||
43 | + traceEtats(tabcomp); | ||
44 | + | ||
45 | + /* }catch(NonConnecteException ex){ | ||
46 | + //throw new NonConnecteException(); | ||
47 | + }*/ | ||
48 | + System.out.println("Au revoir!"); | ||
49 | + } | ||
50 | + | ||
51 | + | ||
52 | + | ||
53 | + | ||
54 | + static void printIds(Composant[] tabc){ | ||
55 | + for(Composant r : tabc){ | ||
56 | + System.out.println(r.getId()); | ||
57 | + } | ||
58 | + } | ||
59 | + static void description(Composant[] tabc){ | ||
60 | + for(Composant r : tabc){ | ||
61 | + System.out.println(r.description()); | ||
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + | ||
66 | + | ||
67 | + /*static void traceEtats(Composant[] tabc){ | ||
68 | + description(tabc); | ||
69 | + getEtat(tabc); | ||
70 | + }*/ | ||
71 | + | ||
72 | + | ||
73 | + /* static void traceEtats(Composant[] tabc) { | ||
74 | + description(tabc); | ||
75 | + for(Composant r : tabc){ | ||
76 | + try{ | ||
77 | + System.out.println(r.getEtat()); | ||
78 | + }catch(NonConnecteException ex){ | ||
79 | + //throw new NonConnecteException(); | ||
80 | + } | ||
81 | + | ||
82 | + } | ||
83 | + }*/ | ||
84 | + static void traceEtats(Composant[] tabc){ | ||
85 | + for(Composant r : tabc){ | ||
86 | + System.out.println( r.traceEtat() ); | ||
87 | + | ||
88 | + } | ||
89 | + } | ||
90 | + | ||
91 | +} |
No preview for this file type
1 | +++ a/TestCircuits.java | ||
@@ -0,0 +1,94 @@ | @@ -0,0 +1,94 @@ | ||
1 | +import java.util.Scanner; | ||
2 | +/** | ||
3 | + * | ||
4 | + * @author rsimonin@polytech-lille.fr | ||
5 | + */ | ||
6 | + | ||
7 | +public class TestCircuits { | ||
8 | + | ||
9 | + public static void main(String[] args) { | ||
10 | + //Construction | ||
11 | + Composant tabcomp[]= new Composant[7] ; | ||
12 | + Or c1=new Or(); | ||
13 | + And c2= new And(); | ||
14 | + Not c3= new Not(); | ||
15 | + Interrupteur i1 = new Interrupteur(); | ||
16 | + Interrupteur i2 = new Interrupteur(); | ||
17 | + Interrupteur i3 = new Interrupteur(); | ||
18 | + Vanne v1= new Vanne(); | ||
19 | + tabcomp[0]=c1; | ||
20 | + tabcomp[1]=c2; | ||
21 | + tabcomp[2]=c3; | ||
22 | + tabcomp[3]=i1; | ||
23 | + tabcomp[4]=i2; | ||
24 | + tabcomp[5]=i3; | ||
25 | + tabcomp[6]=v1; | ||
26 | + | ||
27 | + | ||
28 | + | ||
29 | + //Connexions | ||
30 | + | ||
31 | + ((Or)tabcomp[0]).setIN1(tabcomp[3]); | ||
32 | + | ||
33 | + ((Or)tabcomp[0]).setIN2(tabcomp[4]); | ||
34 | + ((Not)tabcomp[2]).setIn(tabcomp[5]); | ||
35 | + ((And)tabcomp[1]).setIN1(tabcomp[0]); | ||
36 | + ((And)tabcomp[1]).setIN2(tabcomp[2]); | ||
37 | + ((Vanne)tabcomp[6]).setIn(tabcomp[1]); | ||
38 | + | ||
39 | + c1.setIN1(new LazySonde(c1,"in1")); | ||
40 | + | ||
41 | + Circuit cir = new Circuit("circ",tabcomp); | ||
42 | + test(cir); | ||
43 | + | ||
44 | + //Affichage | ||
45 | + //c1.setIN1(new LazySonde(c1,"in1")); | ||
46 | + | ||
47 | + | ||
48 | + System.out.println("Au revoir!"); | ||
49 | + } | ||
50 | + | ||
51 | + static void test(Circuit circ){ | ||
52 | + circ.unprobe(); | ||
53 | + /*System.out.println("Nomenclature:"); | ||
54 | + System.out.println(circ.nomenclature()); | ||
55 | + System.out.println(); | ||
56 | + System.out.println("description:"); | ||
57 | + circ.description(); | ||
58 | + System.out.println(); | ||
59 | + System.out.println("Interupteurs:"); | ||
60 | + System.out.println(circ.getIns()); | ||
61 | + System.out.println(); | ||
62 | + System.out.println("sorties:"); | ||
63 | + System.out.println(circ.getOuts()); | ||
64 | + System.out.println();*/ | ||
65 | + System.out.println("trace:"); | ||
66 | + circ.traceEtats(); | ||
67 | + | ||
68 | + System.out.println(circ.getIns()); | ||
69 | + System.out.println(circ.getOuts()); | ||
70 | + circ.probe(); | ||
71 | + //circ.resetSondes(); | ||
72 | + | ||
73 | + | ||
74 | + } | ||
75 | + | ||
76 | + | ||
77 | + static void printIds(Composant[] tabc){ | ||
78 | + for(Composant r : tabc){ | ||
79 | + System.out.println(r.getId()); | ||
80 | + } | ||
81 | + } | ||
82 | + static void description(Composant[] tabc){ | ||
83 | + for(Composant r : tabc){ | ||
84 | + System.out.println(r.description()); | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + static void traceEtats(Composant[] tabc){ | ||
89 | + for(Composant r : tabc){ | ||
90 | + System.out.println( r.traceEtat() ); | ||
91 | + | ||
92 | + } | ||
93 | + } | ||
94 | +} |
1 | +++ a/TestCircuits.java~ | ||
@@ -0,0 +1,87 @@ | @@ -0,0 +1,87 @@ | ||
1 | +import java.util.Scanner; | ||
2 | +/** | ||
3 | + * | ||
4 | + * @author Bernard.Carre@polytech-lille.fr | ||
5 | + */ | ||
6 | + | ||
7 | +public class TestCircuits { | ||
8 | + | ||
9 | + public static void main(String[] args) { | ||
10 | + //Construction | ||
11 | + Composant tabcomp[]= new Composant[7] ; | ||
12 | + Or c1=new Or(); | ||
13 | + And c2= new And(); | ||
14 | + Not c3= new Not(); | ||
15 | + Interrupteur i1 = new Interrupteur(); | ||
16 | + Interrupteur i2 = new Interrupteur(); | ||
17 | + Interrupteur i3 = new Interrupteur(); | ||
18 | + Vanne v1= new Vanne(); | ||
19 | + tabcomp[0]=c1; | ||
20 | + tabcomp[1]=c2; | ||
21 | + tabcomp[2]=c3; | ||
22 | + tabcomp[3]=i1; | ||
23 | + tabcomp[4]=i2; | ||
24 | + tabcomp[5]=i3; | ||
25 | + tabcomp[6]=v1; | ||
26 | + | ||
27 | + | ||
28 | + | ||
29 | + //Connexions | ||
30 | + | ||
31 | + ((Or)tabcomp[0]).setIN1(tabcomp[3]); | ||
32 | + | ||
33 | + ((Or)tabcomp[0]).setIN2(tabcomp[4]); | ||
34 | + ((Not)tabcomp[2]).setIn(tabcomp[5]); | ||
35 | + ((And)tabcomp[1]).setIN1(tabcomp[0]); | ||
36 | + ((And)tabcomp[1]).setIN2(tabcomp[2]); | ||
37 | + ((Vanne)tabcomp[6]).setIn(tabcomp[1]); | ||
38 | + | ||
39 | + c1.setIN1(new LazySonde(c1,"in1")); | ||
40 | + | ||
41 | + Circuit cir = new Circuit("circ",tabcomp); | ||
42 | + test(cir); | ||
43 | + | ||
44 | + //Affichage | ||
45 | + //c1.setIN1(new LazySonde(c1,"in1")); | ||
46 | + | ||
47 | + | ||
48 | + System.out.println("Au revoir!"); | ||
49 | + } | ||
50 | + | ||
51 | + static void test(Circuit circ){ | ||
52 | + System.out.println("Nomenclature:"); | ||
53 | + System.out.println(circ.nomenclature()); | ||
54 | + System.out.println(); | ||
55 | + System.out.println("description:"); | ||
56 | + circ.description(); | ||
57 | + System.out.println(); | ||
58 | + System.out.println("Interupteurs:"); | ||
59 | + System.out.println(circ.getIns()); | ||
60 | + System.out.println(); | ||
61 | + System.out.println("sorties:"); | ||
62 | + System.out.println(circ.getOuts()); | ||
63 | + System.out.println(); | ||
64 | + System.out.println("trace:"); | ||
65 | + circ.traceEtats(); | ||
66 | + } | ||
67 | + | ||
68 | + | ||
69 | + static void printIds(Composant[] tabc){ | ||
70 | + for(Composant r : tabc){ | ||
71 | + System.out.println(r.getId()); | ||
72 | + } | ||
73 | + } | ||
74 | + static void description(Composant[] tabc){ | ||
75 | + for(Composant r : tabc){ | ||
76 | + System.out.println(r.description()); | ||
77 | + } | ||
78 | + } | ||
79 | + | ||
80 | + static void traceEtats(Composant[] tabc){ | ||
81 | + for(Composant r : tabc){ | ||
82 | + System.out.println( r.traceEtat() ); | ||
83 | + | ||
84 | + } | ||
85 | + } | ||
86 | + | ||
87 | +} |
No preview for this file type
1 | +++ a/Vanne.java | ||
@@ -0,0 +1,39 @@ | @@ -0,0 +1,39 @@ | ||
1 | +/** | ||
2 | + * | ||
3 | + * @author Bernard.Carre@polytech-lille.fr | ||
4 | + */ | ||
5 | + | ||
6 | +public class Vanne extends Composant { | ||
7 | + //... | ||
8 | + | ||
9 | + protected Composant in; | ||
10 | + | ||
11 | + public void setIn(Composant comp) { | ||
12 | + in = comp; | ||
13 | + } | ||
14 | + public void probe(){ | ||
15 | + | ||
16 | + | ||
17 | + } | ||
18 | + | ||
19 | + | ||
20 | + public String description(){ | ||
21 | + String s1 ="non connecté"; | ||
22 | + if(in!=null){s1=in.getId();} | ||
23 | + return getId() + " ||in: " +s1; | ||
24 | + } | ||
25 | + | ||
26 | + | ||
27 | + public boolean getEtat() throws NonConnecteException { | ||
28 | + | ||
29 | + if (in == null) { | ||
30 | + | ||
31 | + throw new NonConnecteException(); | ||
32 | + | ||
33 | + } else { | ||
34 | + | ||
35 | + return in.getEtat(); | ||
36 | + | ||
37 | + } | ||
38 | + } | ||
39 | +} |
1 | +++ a/Vanne.java~ | ||
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +/** | ||
2 | + * | ||
3 | + * @author Bernard.Carre@polytech-lille.fr | ||
4 | + */ | ||
5 | + | ||
6 | +public class Vanne extends Composant { | ||
7 | + //... | ||
8 | + | ||
9 | + protected Composant in; | ||
10 | + | ||
11 | + public void setIn(Composant comp) { | ||
12 | + in = comp; | ||
13 | + } | ||
14 | + | ||
15 | + public String description(){ | ||
16 | + String s1 ="non connecté"; | ||
17 | + if(in!=null){s1=in.getId();} | ||
18 | + return getId() + " ||in: " +s1; | ||
19 | + } | ||
20 | + | ||
21 | + | ||
22 | + public boolean getEtat() throws NonConnecteException { | ||
23 | + | ||
24 | + if (in == null) { | ||
25 | + | ||
26 | + throw new NonConnecteException(); | ||
27 | + | ||
28 | + } else { | ||
29 | + | ||
30 | + return in.getEtat(); | ||
31 | + | ||
32 | + } | ||
33 | + } | ||
34 | +} |