Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The live bourse tracking system codes you created for the observer pattern usage example are as follows, but they do not work. I think the

The live bourse tracking system codes you created for the observer pattern usage example are as follows, but they do not work. I think the main function is missing. Complete it so it works and draw the uml diagram of the final version of the code.
// Subject interface
public interface CurrencyRateTracker {
void registerObserver(Observer o);
void removeObserver(Observer o);
void notifyObservers();
}
// Concrete Subject
public class BourseRateTracker implements CurrencyRateTracker {
private List observers = new ArrayList<>();
private double usdTryRate;
public void setUsdTryRate(double rate){
this.usdTryRate = rate;
notifyObservers();
}
@Override
public void registerObserver(Observer o){
observers.add(o);
}
@Override
public void removeObserver(Observer o){
observers.remove(o);
}
@Override
public void notifyObservers(){
for (Observer observer : observers){
observer.update(usdTryRate);
}
}
}
// Observer interface
public interface Observer {
void update(double usdTryRate);
}
// Concrete Observer
public class CurrencyDisplay implements Observer {
@Override
public void update(double rate){
System.out.println("Updated USD/TRY Rate: "+ rate);
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Understand how managers can improve team effectiveness

Answered: 1 week ago

Question

1. Show enthusiasm for the subject you teach.

Answered: 1 week ago

Question

=+Part 1 What kind of client could use vernacular in the campaign?

Answered: 1 week ago