diff --git a/src/main/java/fr/univlille/iut/r304/tp3/q3/ConnectableProperty.java b/src/main/java/fr/univlille/iut/r304/tp3/q3/ConnectableProperty.java
index ce7269d5ecfe5adf17694c31683a359b9322d7ca..e782319add7b10735ac7cd01c999f84345b9f5ed 100644
--- a/src/main/java/fr/univlille/iut/r304/tp3/q3/ConnectableProperty.java
+++ b/src/main/java/fr/univlille/iut/r304/tp3/q3/ConnectableProperty.java
@@ -1,14 +1,38 @@
package fr.univlille.iut.r304.tp3.q3;
-public class ConnectableProperty extends ObservableProperty {
+import fr.univlille.iut.r304.tp3.q1.Observable;
+import fr.univlille.iut.r304.tp3.q1.Observer;
+public class ConnectableProperty extends ObservableProperty implements Observer{
public void connectTo(ConnectableProperty other) {
+ other.attach(this);
+ other.notifyObservers(other.getValue());
}
public void biconnectTo(ConnectableProperty other) {
+ other.attach(this);
+ this.attach(other);
+ if (!changing){
+ changing=true;
+ other.notifyObservers(other.getValue());
+ this.notifyObservers(this.getValue());
+ }
+ changing=false;
}
public void unconnectFrom(ConnectableProperty other) {
+ other.detach(this);
}
+ @Override
+ public void update(Observable subj) {
+ }
+
+ @Override
+ public void update(Observable subj, Object data) {
+ if (!data.equals(getValue())){
+ setValue(data);
+ }
+
+ }
}
diff --git a/src/main/java/fr/univlille/iut/r304/tp3/q3/ObservableProperty.java b/src/main/java/fr/univlille/iut/r304/tp3/q3/ObservableProperty.java
index b126380c2db52424f68500f08c07cadb10af73c0..07fa58619614d7058d812369edcbc73ffa8ec6c2 100644
--- a/src/main/java/fr/univlille/iut/r304/tp3/q3/ObservableProperty.java
+++ b/src/main/java/fr/univlille/iut/r304/tp3/q3/ObservableProperty.java
@@ -1,24 +1,23 @@
package fr.univlille.iut.r304.tp3.q3;
+import fr.univlille.iut.r304.tp3.q1.Observable;
import fr.univlille.iut.r304.tp3.q1.Observer;
-public class ObservableProperty {
+public class ObservableProperty extends Observable {
+ protected Object value=0;
+ protected boolean changing=false;
public void setValue(Object i) {
+ if(!changing){
+ changing=true;
+ this.value= i;
+ this.notifyObservers(i);
+ }
+ changing=false;
}
public Object getValue() {
- return null;
- }
-
- public void attach(Observer observer) {
- // methode cree pour que les tests compilent sans erreurs
- // n'est pas censée rester une fois que vous avez fini Q2.1
- }
-
- public void detach(Observer observer) {
- // methode cree pour que les tests compilent sans erreur
- // n'est pas censée rester une fois que vous avez fini Q2.1
+ return value;
}
}
diff --git a/src/main/java/fr/univlille/iut/r304/tp3/q4/Devise.java b/src/main/java/fr/univlille/iut/r304/tp3/q4/Devise.java
new file mode 100644
index 0000000000000000000000000000000000000000..a8e74bad2c18469a92e9085a1ef7d705b8483f86
--- /dev/null
+++ b/src/main/java/fr/univlille/iut/r304/tp3/q4/Devise.java
@@ -0,0 +1,46 @@
+package fr.univlille.iut.r304.tp3.q4;
+
+import fr.univlille.iut.r304.tp3.q1.Observable;
+import fr.univlille.iut.r304.tp3.q2.Objectif;
+import fr.univlille.iut.r304.tp3.q2.Texte;
+import fr.univlille.iut.r304.tp3.q3.ConnectableProperty;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+public class Devise extends ConnectableProperty {
+
+ private double valeur=0.0;
+ @Override
+ public void update(Observable subj, Object data) {
+ double taux=1.12;
+ if (!data.equals(getValue())){
+ setValue((double)data*taux);
+ }
+
+ }
+ public double getValeur() {
+ return valeur;
+ }
+
+ public void setValeur(double valeur) {
+ this.valeur = valeur;
+ }
+
+
+ public static void main(String[] args){
+ Devise euro=new Devise();
+ Devise dollar=new Devise();
+ dollar.biconnectTo(euro);
+
+ dollar.setValue(8.0);
+ System.out.println(euro.getValue()+" €");
+ System.out.println(dollar.getValue()+" $");
+
+ dollar.setValue(11.0);
+ System.out.println(euro.getValue()+" €");
+ System.out.println(dollar.getValue()+ " $");
+ }
+
+
+}