Skip to content
Snippets Groups Projects
Commit 46f6acc7 authored by Yvan Serikoff's avatar Yvan Serikoff
Browse files

q3-q4

parent f56c4b4f
No related branches found
No related tags found
No related merge requests found
package fr.univlille.iut.r304.tp3.q3; 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) { public void connectTo(ConnectableProperty other) {
other.attach(this);
other.notifyObservers(other.getValue());
} }
public void biconnectTo(ConnectableProperty other) { public void biconnectTo(ConnectableProperty other) {
this.connectTo(other);
other.connectTo(this);
} }
public void unconnectFrom(ConnectableProperty other) { public void unconnectFrom(ConnectableProperty other) {
other.detach(this);
}
@Override
public void update(Observable o) {
changed = true;
}
@Override
public void update(Observable o, Object arg) {
if (!value.equals(arg)) {
changed = true;
this.setValue(arg);
}
} }
} }
package fr.univlille.iut.r304.tp3.q3; package fr.univlille.iut.r304.tp3.q3;
import fr.univlille.iut.r304.tp3.q1.Observable;
import fr.univlille.iut.r304.tp3.q1.Observer; import fr.univlille.iut.r304.tp3.q1.Observer;
public class ObservableProperty { public class ObservableProperty extends Observable {
protected Object value=0;
protected boolean changed=false;
public void setValue(Object i) { public void setValue(Object i) {
value = i;
notifyObservers(value);
} }
public Object getValue() { public Object getValue() {
return null; return value;
}
public void attach(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
}
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
} }
} }
package fr.univlille.iut.r304.tp3.q4;
import fr.univlille.iut.r304.tp3.q3.ConnectableProperty;
import fr.univlille.iut.r304.tp3.q1.Observable;
import javax.security.auth.Subject;
public class Devise extends ConnectableProperty {
private double conversionRate;
private String symbol;
public Devise(double conversionRate, char symbol) {
super();
this.conversionRate = conversionRate;
this.symbol = symbol;
}
public double getConversionRate() {
return this.conversionRate;
}
public String getSymbol() {
return this.symbol;
}
public void update(Subject o, Object data) {
String dataString = (String) data;
int index = dataString.indexOf(symbol);
if (dataString.contains(symbol)){
this.notifyObservers();
}
}
}
\ No newline at end of file
package fr.univlille.iut.r304.tp3.q4;
public class Main {
public static void main(String[] args) {
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment