diff --git a/#Not.java# b/#Not.java# new file mode 100755 index 0000000..7d71fc0 --- /dev/null +++ b/#Not.java# @@ -0,0 +1,36 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public class Not extends Porte { + //... + protected Composant in; + + public void setIn(Composant comp) { + in = comp; + } + public void probe(SondesTable tableSondes){ + if(in instanceof Interrupteur){ + getSonde(in,in, + } + } + public String description(){ + return getId() + " ||in: "+ in.getId(); + } + + + public boolean getEtat() throws NonConnecteException { + + if (in == null) { + + throw new NonConnecteException(); + + } else { + + return !in.getEtat(); + + } + } + +} diff --git a/#Porte2Entrees.java# b/#Porte2Entrees.java# new file mode 100644 index 0000000..983460c --- /dev/null +++ b/#Porte2Entrees.java# @@ -0,0 +1,53 @@ + + +public abstract class Porte2Entrees extends Porte { + Composant in1,in2; + Boolean s; + + void setIN1(Composant comp){in1= comp;} + void setIN2(Composant comp){in2= comp;} + + public String description(){ + String s1 ="non connecté"; + String s2 ="non connecté"; + if(in1!=null){s1=in1.getId();} + if(in2!=null){s2=in2.getId();} + return getId() +" ||in1: " + s1 +" ||in2: "+ s2; + } + public abstract boolean eval()throws NonConnecteException; + + public void probe(SondesTable tableSondes){ + if(in1 instanceof Interrupteur){ + tableSondes.getSonde((Interrupteur)in1,in1,in1.getId()); + } + if(in2 instanceof Interrupteur){ + tableSondes.getSonde((Interrupteur)in2,in2,in2.getId()); + } + } + public void unprobe(SondesTable tableSondes){ + if(in1 instanceof LazySonde){ + tableSondes.getInterrupteur((LazySonde)in1); + } + if(in2 instanceof LazySonde){ + tableSondes.getInterrupteur((LazySonde)in2); + } + } + + /*public boolean getEtat() throws NonConnecteException { + if ((this.in1 == null) || (this.in2 == null)) { + throw new NonConnecteException(); + } + else if(s==null) { + s=this.eval(); + return s; + } + else{ return s;} + }*/ + public boolean getEtat() throws NonConnecteException { + if ((this.in1 == null) || (this.in2 == null)) { + throw new NonConnecteException(); + } + else { + return this.eval(); + } +} diff --git a/#SondeTable.java# b/#SondeTable.java# new file mode 100644 index 0000000..2832fc2 --- /dev/null +++ b/#SondeTable.java# @@ -0,0 +1,3 @@ +import java.util.* ; + +public class Sondes \ No newline at end of file diff --git a/And.class b/And.class new file mode 100644 index 0000000..15daabb Binary files /dev/null and b/And.class differ diff --git a/And.java b/And.java new file mode 100644 index 0000000..e77b711 --- /dev/null +++ b/And.java @@ -0,0 +1,19 @@ +public class And extends Porte2Entrees{ + /*void run(){ + s=in1 && in2; + } + void display(){ + }*/ + /*public boolean getEtat() throws NonConnecteException { + if ((in1 == null) || (in2 == null)) { + throw new NonConnecteException(); + } else { + s=(in1.getEtat() && in2.getEtat()); + return s; + } + }*/ + + public boolean eval()throws NonConnecteException { + return (in1.getEtat() && in2.getEtat()); + } +} diff --git a/And.java~ b/And.java~ new file mode 100644 index 0000000..919a8c3 --- /dev/null +++ b/And.java~ @@ -0,0 +1,24 @@ +public class And extends Porte2Entrees{ + /*void run(){ + s=in1 && in2; + } + void display(){ + }*/ + /*public boolean getEtat() throws NonConnecteException { + if ((in1 == null) || (in2 == null)) { + throw new NonConnecteException(); + } else { + s=(in1.getEtat() && in2.getEtat()); + return s; + } + }*/ + + public boolean eval(){ + if ((in1 == null) || (in2 == null)) { + throw new NonConnecteException(); + } else { + s=(in1.getEtat() && in2.getEtat()); + return s; + } + } +} diff --git a/Circuit.class b/Circuit.class new file mode 100644 index 0000000..e2321f5 Binary files /dev/null and b/Circuit.class differ diff --git a/Circuit.java b/Circuit.java new file mode 100644 index 0000000..0648411 --- /dev/null +++ b/Circuit.java @@ -0,0 +1,70 @@ +import java.util.* ; + +public class Circuit { + String Nom; + java.util.List composants = new ArrayList(); + + protected SondesTable tableSondes = new SondesTable(); + + public void traceEtats(){ + System.out.println(Nom ); + for(Composant r : composants){ + System.out.println( r.traceEtat() ); + } + } + + + public List nomenclature(){ + java.util.List res= new ArrayList(); + for(Composant r : composants){ + res.add(r.getId()); + } + return res; + } + + public List getIns(){ + java.util.List res = new ArrayList(); + for(Composant r : composants){ + if(r instanceof Interrupteur){res.add((Interrupteur)r);} + } + return res; + } + public void description(){ + System.out.println(Nom ); + for(Composant r : composants){ + System.out.println( r.description() ); + } + } + + public List getOuts(){ + java.util.List res = new ArrayList(); + for(Composant r : composants){ + if(r instanceof Vanne){res.add((Vanne)r);} + } + return res; + } + + public Circuit(String nom, Composant[] cps){ + Nom=nom; + composants.addAll(Arrays.asList(cps)); + Collections.sort(composants); + } + + public void probe(){ + for(Composant c : composants){ + if(c instanceof Porte){ ((Porte)c).probe(tableSondes);} + } + } + public void resetSondes(){ + tableSondes.resetSondes(); + } + public void unprobe(){ + for(Composant c : composants){ + if(c instanceof Porte){((Porte)c).unprobe(tableSondes);} + } + } + + + + +} diff --git a/Circuit.java~ b/Circuit.java~ new file mode 100644 index 0000000..c1914e0 --- /dev/null +++ b/Circuit.java~ @@ -0,0 +1,70 @@ +import java.util.* ; + +public class Circuit { + String Nom; + java.util.List composants = new ArrayList(); + + protected SondesTable tableSondes = new SondesTable(); + + public void traceEtats(){ + System.out.println(Nom ); + for(Composant r : composants){ + System.out.println( r.traceEtat() ); + } + } + + + public List nomenclature(){ + java.util.List res= new ArrayList(); + for(Composant r : composants){ + res.add(r.getId()); + } + return res; + } + + public List getIns(){ + java.util.List res = new ArrayList(); + for(Composant r : composants){ + if(r instanceof Interrupteur){res.add((Interrupteur)r);} + } + return res; + } + public void description(){ + System.out.println(Nom ); + for(Composant r : composants){ + System.out.println( r.description() ); + } + } + + public List getOuts(){ + java.util.List res = new ArrayList(); + for(Composant r : composants){ + if(r instanceof Vanne){res.add((Vanne)r);} + } + return res; + } + + public Circuit(String nom, Composant[] cps){ + Nom=nom; + composants.addAll(Arrays.asList(cps)); + Collections.sort(composants); + } + + public void probe(){ + for(Composant c : composants){ + ((Porte)c).probe(tableSondes); + } + } + public void resetSondes(){ + tableSondes.resetSondes(); + } + public void unprobe(){ + for(Composant c : composants){ + ((Porte)c).unprobe(tableSondes); + } + } + + + + +} diff --git a/Composant.class b/Composant.class new file mode 100644 index 0000000..7428955 Binary files /dev/null and b/Composant.class differ diff --git a/Composant.java b/Composant.java new file mode 100755 index 0000000..277b59e --- /dev/null +++ b/Composant.java @@ -0,0 +1,29 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public abstract class Composant implements Comparable { + //... + public String getId() { + + return super.toString(); // class@numero renvoye par Object + + } + public abstract String description(); + public abstract boolean getEtat() throws NonConnecteException; + + public String traceEtat(){ + String s = this.description(); + + try{ + s=s+" "+ this.getEtat(); + }catch(NonConnecteException ex){ + s=s+" non connecte"; + } + return s; + } + public int compareTo(Composant c) { + return (this.getId()).compareTo(c.getId()); + } +} diff --git a/Composant.java~ b/Composant.java~ new file mode 100755 index 0000000..1dad3b4 --- /dev/null +++ b/Composant.java~ @@ -0,0 +1,29 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public abstract class Composant implements Comparable { + //... + public String getId() { + + return super.toString(); // class@numero renvoye par Object + + } + public abstract String description(); + public abstract boolean getEtat() throws NonConnecteException; + public abstract void probe(); + public String traceEtat(){ + String s = this.description(); + + try{ + s=s+" "+ this.getEtat(); + }catch(NonConnecteException ex){ + s=s+" non connecte"; + } + return s; + } + public int compareTo(Composant c) { + return (this.getId()).compareTo(c.getId()); + } +} diff --git a/Interrupteur.class b/Interrupteur.class new file mode 100644 index 0000000..4f87f0e Binary files /dev/null and b/Interrupteur.class differ diff --git a/Interrupteur.java b/Interrupteur.java new file mode 100755 index 0000000..4994ab6 --- /dev/null +++ b/Interrupteur.java @@ -0,0 +1,33 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + + +public class Interrupteur extends Composant { + //... + + protected boolean etat; + + public void on() { + + etat = true; + + } + + public void off() { + + etat = false; + + } + + public boolean getEtat() throws NonConnecteException { + + return etat; + + } + public String description(){ + return getId(); + } + +} diff --git a/Interrupteur.java~ b/Interrupteur.java~ new file mode 100755 index 0000000..890cdfa --- /dev/null +++ b/Interrupteur.java~ @@ -0,0 +1,33 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + + +public class Interrupteur extends Composant { + //... + + protected boolean etat; + + public void on() { + + etat = true; + + } + + public void off() { + + etat = false; + + } + + public boolean getEtat() throws NonConnecteException { + + return etat; + + } + public String description(){ + return getId(); + } + +} diff --git a/LazySonde.class b/LazySonde.class new file mode 100644 index 0000000..2e68932 Binary files /dev/null and b/LazySonde.class differ diff --git a/LazySonde.java b/LazySonde.java new file mode 100644 index 0000000..5754b75 --- /dev/null +++ b/LazySonde.java @@ -0,0 +1,40 @@ +import java.util.Scanner; +public class LazySonde extends Sonde{ + Boolean valsor; + + LazySonde(Composant c, String str){ + c1=c; + str1=str; + } + + LazySonde(){ + c1=null; + str1=null; + } + public boolean getEtat() throws NonConnecteException{ + System.out.println(" je suis lazy SONNNNDEE"); + Scanner sc = new Scanner(System.in); + if (str1 == null) { + throw new NonConnecteException(); + } + else if(valsor!=null){return valsor;} + + else { + System.out.println(str1+ " de " + c1 + " ,true ou false ? " ); + + if (sc.hasNextBoolean()) { + valsor = sc.nextBoolean(); + return valsor; + } + else { + System.out.println("Nous avons pas compris votre choix, la valeur par default est false !"); + return false; + } + } + } + + public void reset(){ + valsor=null; + return ; + } +} diff --git a/LazySonde.java~ b/LazySonde.java~ new file mode 100644 index 0000000..56efac7 --- /dev/null +++ b/LazySonde.java~ @@ -0,0 +1,40 @@ +import java.util.Scanner; +public class LazySonde extends Sonde{ + Boolean valsor; + + LazySonde(Composant c, String str){ + c1=c; + str1=str; + } + + LazySonde(){ + c1=null; + str1=null; + } + public boolean getEtat() throws NonConnecteException{ + System.out.println(" je suis lazy SONNNNDEE"); + Scanner sc = new Scanner(System.in); + if (str1 == null) { + throw new NonConnecteException(); + } + else if(valsor!=null){return valsor;} + + else { + System.out.println(str1+ " de " + c1 + " ,true ou false ? " ); + + if (sc.hasNextBoolean()) { + valsor = sc.nextBoolean(); + return valsor; + } + else { + System.out.println("Nous avons pas compris votre choix, la valeur par default est false !"); + return false; + } + } + } + + public void reset(){ + this.valsor=null; + return ; + } +} diff --git a/NonConnecteException.class b/NonConnecteException.class new file mode 100644 index 0000000..9910f2a Binary files /dev/null and b/NonConnecteException.class differ diff --git a/NonConnecteException.java b/NonConnecteException.java new file mode 100755 index 0000000..e114526 --- /dev/null +++ b/NonConnecteException.java @@ -0,0 +1,6 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public class NonConnecteException extends Exception {} \ No newline at end of file diff --git a/Not.class b/Not.class new file mode 100644 index 0000000..faa9936 Binary files /dev/null and b/Not.class differ diff --git a/Not.java b/Not.java new file mode 100755 index 0000000..f960ced --- /dev/null +++ b/Not.java @@ -0,0 +1,40 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public class Not extends Porte { + + protected Composant in; + + public void setIn(Composant comp) { + in = comp; + } + public void probe(SondesTable tableSondes){ + if(in instanceof Interrupteur){ + System.out.println(tableSondes.getSonde((Interrupteur)in,in,in.getId())); + } + } + public String description(){ + return getId() + " ||in: "+ in.getId(); + } + + + public boolean getEtat() throws NonConnecteException { + + if (in == null) { + + throw new NonConnecteException(); + + } else { + + return !in.getEtat(); + + } + } + public void unprobe(SondesTable tableSondes){ + if(in instanceof LazySonde){ + System.out.println(tableSondes.getInterrupteur((LazySonde)in)); + } + } +} diff --git a/Not.java~ b/Not.java~ new file mode 100755 index 0000000..cf99aac --- /dev/null +++ b/Not.java~ @@ -0,0 +1,36 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public class Not extends Porte { + //... + protected Composant in; + + public void setIn(Composant comp) { + in = comp; + } + public void probe(SondesTable tableSondes){ + if(in instanceof Interrupteur){ + tableSondes.getSonde((Interrupteur)in,in,in.getId()); + } + } + public String description(){ + return getId() + " ||in: "+ in.getId(); + } + + + public boolean getEtat() throws NonConnecteException { + + if (in == null) { + + throw new NonConnecteException(); + + } else { + + return !in.getEtat(); + + } + } + +} diff --git a/Or.class b/Or.class new file mode 100644 index 0000000..54f0a87 Binary files /dev/null and b/Or.class differ diff --git a/Or.java b/Or.java new file mode 100644 index 0000000..51b9c10 --- /dev/null +++ b/Or.java @@ -0,0 +1,21 @@ +public class Or extends Porte2Entrees{ + /* void run(){ + s=in1 || in2; + } + void display(){ + }*/ + + /*public boolean getEtat() throws NonConnecteException { + if ((in1 == null) || (in2 == null)) { + throw new NonConnecteException(); + } else { + s=(in1.getEtat() || in2.getEtat()); + return s; + } + }*/ + + public boolean eval() throws NonConnecteException{ + return (in1.getEtat() || in2.getEtat()); + } + +} diff --git a/Or.java~ b/Or.java~ new file mode 100644 index 0000000..0bb35d1 --- /dev/null +++ b/Or.java~ @@ -0,0 +1,26 @@ +public class Or extends Porte2Entrees{ + /* void run(){ + s=in1 || in2; + } + void display(){ + }*/ + + /*public boolean getEtat() throws NonConnecteException { + if ((in1 == null) || (in2 == null)) { + throw new NonConnecteException(); + } else { + s=(in1.getEtat() || in2.getEtat()); + return s; + } + }*/ + + public boolean eval(){ + if ((in1 == null) || (in2 == null)) { + throw new NonConnecteException(); + } else { + s=(in1.getEtat() || in2.getEtat()); + return s; + } + } + +} diff --git a/Porte.class b/Porte.class new file mode 100644 index 0000000..7d62b39 Binary files /dev/null and b/Porte.class differ diff --git a/Porte.java b/Porte.java new file mode 100755 index 0000000..0d5f48e --- /dev/null +++ b/Porte.java @@ -0,0 +1,9 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public abstract class Porte extends Composant { + public abstract void unprobe(SondesTable tableSondes); + public abstract void probe(SondesTable tableSondes); +} diff --git a/Porte.java~ b/Porte.java~ new file mode 100755 index 0000000..32aa0d1 --- /dev/null +++ b/Porte.java~ @@ -0,0 +1,8 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public abstract class Porte extends Composant { + public abstract void probe(SondesTable tableSondes); +} diff --git a/Porte2Entrees.class b/Porte2Entrees.class new file mode 100644 index 0000000..867f25b Binary files /dev/null and b/Porte2Entrees.class differ diff --git a/Porte2Entrees.java b/Porte2Entrees.java new file mode 100644 index 0000000..07e567f --- /dev/null +++ b/Porte2Entrees.java @@ -0,0 +1,54 @@ + + +public abstract class Porte2Entrees extends Porte { + Composant in1,in2; + Boolean s; + + void setIN1(Composant comp){in1= comp;} + void setIN2(Composant comp){in2= comp;} + + public String description(){ + String s1 ="non connecté"; + String s2 ="non connecté"; + if(in1!=null){s1=in1.getId();} + if(in2!=null){s2=in2.getId();} + return getId() +" ||in1: " + s1 +" ||in2: "+ s2; + } + public abstract boolean eval()throws NonConnecteException; + + public void probe(SondesTable tableSondes){ + if(in1 instanceof Interrupteur){ + tableSondes.getSonde((Interrupteur)in1,in1,in1.getId()); + } + if(in2 instanceof Interrupteur){ + tableSondes.getSonde((Interrupteur)in2,in2,in2.getId()); + } + } + public void unprobe(SondesTable tableSondes){ + if(in1 instanceof LazySonde){ + tableSondes.getInterrupteur((LazySonde)in1); + } + if(in2 instanceof LazySonde){ + tableSondes.getInterrupteur((LazySonde)in2); + } + } + + /*public boolean getEtat() throws NonConnecteException { + if ((this.in1 == null) || (this.in2 == null)) { + throw new NonConnecteException(); + } + else if(s==null) { + s=this.eval(); + return s; + } + else{ return s;} + }*/ + public boolean getEtat() throws NonConnecteException { + if ((this.in1 == null) || (this.in2 == null)) { + throw new NonConnecteException(); + } + else { + return this.eval(); + } + } +} diff --git a/Porte2Entrees.java~ b/Porte2Entrees.java~ new file mode 100644 index 0000000..7e7e68f --- /dev/null +++ b/Porte2Entrees.java~ @@ -0,0 +1,54 @@ + + +public abstract class Porte2Entrees extends Porte { + Composant in1,in2; + Boolean s; + + void setIN1(Composant comp){in1= comp;} + void setIN2(Composant comp){in2= comp;} + + public String description(){ + String s1 ="non connecté"; + String s2 ="non connecté"; + if(in1!=null){s1=in1.getId();} + if(in2!=null){s2=in2.getId();} + return getId() +" ||in1: " + s1 +" ||in2: "+ s2; + } + public abstract boolean eval()throws NonConnecteException; + + public void probe(SondesTable tableSondes){ + if(in1 instanceof Interrupteur){ + tableSondes.getSonde((Interrupteur)in1,in1,in1.getId()); + } + if(in2 instanceof Interrupteur){ + tableSondes.getSonde((Interrupteur)in2,in2,in2.getId()); + } + } + public void unprobe(SondesTable tableSondes){ + if(in1 instanceof Interrupteur){ + tableSondes.getInterrupteur(in1); + } + if(in2 instanceof Interrupteur){ + tableSondes.getInterrupteur(in2); + } + } + + /*public boolean getEtat() throws NonConnecteException { + if ((this.in1 == null) || (this.in2 == null)) { + throw new NonConnecteException(); + } + else if(s==null) { + s=this.eval(); + return s; + } + else{ return s;} + }*/ + public boolean getEtat() throws NonConnecteException { + if ((this.in1 == null) || (this.in2 == null)) { + throw new NonConnecteException(); + } + else { + return this.eval(); + } + } +} diff --git a/Sonde.class b/Sonde.class new file mode 100644 index 0000000..6c308c3 Binary files /dev/null and b/Sonde.class differ diff --git a/Sonde.java b/Sonde.java new file mode 100644 index 0000000..3129978 --- /dev/null +++ b/Sonde.java @@ -0,0 +1,19 @@ +import java.util.Scanner; +public abstract class Sonde extends Composant{ + Composant c1; + String str1; + Sonde(Composant c, String str){ + c1=c; + str1=str; + } + + Sonde(){ + c1=null; + str1=null; + } + public abstract boolean getEtat() throws NonConnecteException; + + public String description(){ + return c1 + str1 ; + } +} diff --git a/Sonde.java~ b/Sonde.java~ new file mode 100644 index 0000000..4a42195 --- /dev/null +++ b/Sonde.java~ @@ -0,0 +1,36 @@ +import java.util.Scanner; +public abstract class Sonde extends Composant{ + Composant c1; + String str1; + Sonde(Composant c, String str){ + c1=c; + str1=str; + } + + Sonde(){ + c1=null; + str1=null; + } + public abstract boolean getEtat() throws NonConnecteException; + /*public boolean getEtat() throws NonConnecteException{ + Scanner sc = new Scanner(System.in); + if (str1 == null) { + throw new NonConnecteException(); + } else { + System.out.println(str1+ " de " + c1 + " ,true ou false ? " ); + + if (sc.hasNextBoolean()) { + boolean str = sc.nextBoolean(); + return str; + } + else { + System.out.println("Nous avons pas compris votre choix, la valeur par default est false !"); + return false; + } + } + }*/ + + public String description(){ + return c1 + str1 ; + } +} diff --git a/SondesTable.class b/SondesTable.class new file mode 100644 index 0000000..c031fcf Binary files /dev/null and b/SondesTable.class differ diff --git a/SondesTable.java b/SondesTable.java new file mode 100644 index 0000000..1a56db2 --- /dev/null +++ b/SondesTable.java @@ -0,0 +1,38 @@ +import java.util.* ; + +public class SondesTable{ + Map sondetointerrupteur = new HashMap(); + Map interrupteurtosonde = new HashMap(); + + + public Interrupteur getInterrupteur(LazySonde sonde){ + return sondetointerrupteur.get(sonde); + } + + public LazySonde getSonde(Interrupteur interrupteur,Composant cible, String entree){ + + if(interrupteurtosonde.containsKey(interrupteur)){ + return interrupteurtosonde.get(interrupteur) ; + } + else{ + LazySonde lz1= new LazySonde(cible,entree); + interrupteurtosonde.put(interrupteur,lz1); + sondetointerrupteur.put(lz1,interrupteur); + return interrupteurtosonde.get(interrupteur) ; + } + } + public void resetSondes(){ + for( LazySonde e :interrupteurtosonde.values()){ + e.reset(); + } + + return ; + } + public void clear(){ + sondetointerrupteur.clear(); + interrupteurtosonde.clear(); + return ; + } + + +} diff --git a/SondesTable.java~ b/SondesTable.java~ new file mode 100644 index 0000000..0c26d4c --- /dev/null +++ b/SondesTable.java~ @@ -0,0 +1,26 @@ +import java.util.* ; + +public class SondesTable{ + Map< Sonde,Interrupteur> sondetointerrupteur = new HashMap< Sonde,Interrupteur>(); + Map interrupteurtosonde = new HashMap(); + + + public Interrupteur getInterrupteur(LazySonde sonde){ + return sondetointerrupteur.get(sonde); + + + } + + public LazySonde getSonde(Interrupteur interrupteur,Composant cible, String entree){ + return ; + } + public void resetSondes(){ + for( + return ; + } + public void clear(){ + return ; + } + + +} diff --git a/TESTcircuit.txt b/TESTcircuit.txt new file mode 100644 index 0000000..cf5ee89 --- /dev/null +++ b/TESTcircuit.txt @@ -0,0 +1,91 @@ +import java.util.Scanner; +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public class TestCircuits { + + public static void main(String[] args) { + //Construction + Composant tabcomp[]= new Composant[7] ; + Or c1=new Or(); + And c2= new And(); + Not c3= new Not(); + Interrupteur i1 = new Interrupteur(); + Interrupteur i2 = new Interrupteur(); + Interrupteur i3 = new Interrupteur(); + Vanne v1= new Vanne(); + tabcomp[0]=c1; + tabcomp[1]=c2; + tabcomp[2]=c3; + tabcomp[3]=i1; + tabcomp[4]=i2; + tabcomp[5]=i3; + tabcomp[6]=v1; + + + + //Connexions + + //((Or)tabcomp[0]).setIN1(tabcomp[3]); + + ((Or)tabcomp[0]).setIN2(tabcomp[4]); + ((Not)tabcomp[2]).setIn(tabcomp[5]); + ((And)tabcomp[1]).setIN1(tabcomp[0]); + ((And)tabcomp[1]).setIN2(tabcomp[2]); + ((Vanne)tabcomp[6]).setIn(tabcomp[1]); + + //Affichage + c1.setIN1(new LazySonde(c1,"in1")); + + //try{ + traceEtats(tabcomp); + + /* }catch(NonConnecteException ex){ + //throw new NonConnecteException(); + }*/ + System.out.println("Au revoir!"); + } + + + + + static void printIds(Composant[] tabc){ + for(Composant r : tabc){ + System.out.println(r.getId()); + } + } + static void description(Composant[] tabc){ + for(Composant r : tabc){ + System.out.println(r.description()); + } + } + + + + /*static void traceEtats(Composant[] tabc){ + description(tabc); + getEtat(tabc); + }*/ + + + /* static void traceEtats(Composant[] tabc) { + description(tabc); + for(Composant r : tabc){ + try{ + System.out.println(r.getEtat()); + }catch(NonConnecteException ex){ + //throw new NonConnecteException(); + } + + } + }*/ + static void traceEtats(Composant[] tabc){ + for(Composant r : tabc){ + System.out.println( r.traceEtat() ); + + } + } + +} diff --git a/TestCircuits.class b/TestCircuits.class new file mode 100644 index 0000000..6e06709 Binary files /dev/null and b/TestCircuits.class differ diff --git a/TestCircuits.java b/TestCircuits.java new file mode 100755 index 0000000..148d86e --- /dev/null +++ b/TestCircuits.java @@ -0,0 +1,94 @@ +import java.util.Scanner; +/** + * + * @author rsimonin@polytech-lille.fr + */ + +public class TestCircuits { + + public static void main(String[] args) { + //Construction + Composant tabcomp[]= new Composant[7] ; + Or c1=new Or(); + And c2= new And(); + Not c3= new Not(); + Interrupteur i1 = new Interrupteur(); + Interrupteur i2 = new Interrupteur(); + Interrupteur i3 = new Interrupteur(); + Vanne v1= new Vanne(); + tabcomp[0]=c1; + tabcomp[1]=c2; + tabcomp[2]=c3; + tabcomp[3]=i1; + tabcomp[4]=i2; + tabcomp[5]=i3; + tabcomp[6]=v1; + + + + //Connexions + + ((Or)tabcomp[0]).setIN1(tabcomp[3]); + + ((Or)tabcomp[0]).setIN2(tabcomp[4]); + ((Not)tabcomp[2]).setIn(tabcomp[5]); + ((And)tabcomp[1]).setIN1(tabcomp[0]); + ((And)tabcomp[1]).setIN2(tabcomp[2]); + ((Vanne)tabcomp[6]).setIn(tabcomp[1]); + + c1.setIN1(new LazySonde(c1,"in1")); + + Circuit cir = new Circuit("circ",tabcomp); + test(cir); + + //Affichage + //c1.setIN1(new LazySonde(c1,"in1")); + + + System.out.println("Au revoir!"); + } + + static void test(Circuit circ){ + circ.unprobe(); + /*System.out.println("Nomenclature:"); + System.out.println(circ.nomenclature()); + System.out.println(); + System.out.println("description:"); + circ.description(); + System.out.println(); + System.out.println("Interupteurs:"); + System.out.println(circ.getIns()); + System.out.println(); + System.out.println("sorties:"); + System.out.println(circ.getOuts()); + System.out.println();*/ + System.out.println("trace:"); + circ.traceEtats(); + + System.out.println(circ.getIns()); + System.out.println(circ.getOuts()); + circ.probe(); + //circ.resetSondes(); + + + } + + + static void printIds(Composant[] tabc){ + for(Composant r : tabc){ + System.out.println(r.getId()); + } + } + static void description(Composant[] tabc){ + for(Composant r : tabc){ + System.out.println(r.description()); + } + } + + static void traceEtats(Composant[] tabc){ + for(Composant r : tabc){ + System.out.println( r.traceEtat() ); + + } + } +} diff --git a/TestCircuits.java~ b/TestCircuits.java~ new file mode 100755 index 0000000..fa421e6 --- /dev/null +++ b/TestCircuits.java~ @@ -0,0 +1,87 @@ +import java.util.Scanner; +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public class TestCircuits { + + public static void main(String[] args) { + //Construction + Composant tabcomp[]= new Composant[7] ; + Or c1=new Or(); + And c2= new And(); + Not c3= new Not(); + Interrupteur i1 = new Interrupteur(); + Interrupteur i2 = new Interrupteur(); + Interrupteur i3 = new Interrupteur(); + Vanne v1= new Vanne(); + tabcomp[0]=c1; + tabcomp[1]=c2; + tabcomp[2]=c3; + tabcomp[3]=i1; + tabcomp[4]=i2; + tabcomp[5]=i3; + tabcomp[6]=v1; + + + + //Connexions + + ((Or)tabcomp[0]).setIN1(tabcomp[3]); + + ((Or)tabcomp[0]).setIN2(tabcomp[4]); + ((Not)tabcomp[2]).setIn(tabcomp[5]); + ((And)tabcomp[1]).setIN1(tabcomp[0]); + ((And)tabcomp[1]).setIN2(tabcomp[2]); + ((Vanne)tabcomp[6]).setIn(tabcomp[1]); + + c1.setIN1(new LazySonde(c1,"in1")); + + Circuit cir = new Circuit("circ",tabcomp); + test(cir); + + //Affichage + //c1.setIN1(new LazySonde(c1,"in1")); + + + System.out.println("Au revoir!"); + } + + static void test(Circuit circ){ + System.out.println("Nomenclature:"); + System.out.println(circ.nomenclature()); + System.out.println(); + System.out.println("description:"); + circ.description(); + System.out.println(); + System.out.println("Interupteurs:"); + System.out.println(circ.getIns()); + System.out.println(); + System.out.println("sorties:"); + System.out.println(circ.getOuts()); + System.out.println(); + System.out.println("trace:"); + circ.traceEtats(); + } + + + static void printIds(Composant[] tabc){ + for(Composant r : tabc){ + System.out.println(r.getId()); + } + } + static void description(Composant[] tabc){ + for(Composant r : tabc){ + System.out.println(r.description()); + } + } + + static void traceEtats(Composant[] tabc){ + for(Composant r : tabc){ + System.out.println( r.traceEtat() ); + + } + } + +} diff --git a/Vanne.class b/Vanne.class new file mode 100644 index 0000000..81da3c5 Binary files /dev/null and b/Vanne.class differ diff --git a/Vanne.java b/Vanne.java new file mode 100755 index 0000000..94ed2b2 --- /dev/null +++ b/Vanne.java @@ -0,0 +1,39 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public class Vanne extends Composant { + //... + + protected Composant in; + + public void setIn(Composant comp) { + in = comp; + } + public void probe(){ + + + } + + + public String description(){ + String s1 ="non connecté"; + if(in!=null){s1=in.getId();} + return getId() + " ||in: " +s1; + } + + + public boolean getEtat() throws NonConnecteException { + + if (in == null) { + + throw new NonConnecteException(); + + } else { + + return in.getEtat(); + + } + } +} diff --git a/Vanne.java~ b/Vanne.java~ new file mode 100755 index 0000000..76a3284 --- /dev/null +++ b/Vanne.java~ @@ -0,0 +1,34 @@ +/** + * + * @author Bernard.Carre@polytech-lille.fr + */ + +public class Vanne extends Composant { + //... + + protected Composant in; + + public void setIn(Composant comp) { + in = comp; + } + + public String description(){ + String s1 ="non connecté"; + if(in!=null){s1=in.getId();} + return getId() + " ||in: " +s1; + } + + + public boolean getEtat() throws NonConnecteException { + + if (in == null) { + + throw new NonConnecteException(); + + } else { + + return in.getEtat(); + + } + } +} -- libgit2 0.21.2