Skip to content
Snippets Groups Projects
Commit b14e88da authored by Mathys Bollengier's avatar Mathys Bollengier
Browse files

Exo 4

parent 47066685
No related branches found
No related tags found
No related merge requests found
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);
}
}
}
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;
}
}
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()+ " $");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment