forked from rick2785/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrabStocks.java
More file actions
50 lines (32 loc) · 1.34 KB
/
GrabStocks.java
File metadata and controls
50 lines (32 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public class GrabStocks{
public static void main(String[] args){
// Create the Subject object
// It will handle updating all observers
// as well as deleting and adding them
StockGrabber stockGrabber = new StockGrabber();
// Create an Observer that will be sent updates from Subject
StockObserver observer1 = new StockObserver(stockGrabber);
stockGrabber.setIBMPrice(197.00);
stockGrabber.setAAPLPrice(677.60);
stockGrabber.setGOOGPrice(676.40);
StockObserver observer2 = new StockObserver(stockGrabber);
stockGrabber.setIBMPrice(197.00);
stockGrabber.setAAPLPrice(677.60);
stockGrabber.setGOOGPrice(676.40);
// Delete one of the observers
// stockGrabber.unregister(observer2);
stockGrabber.setIBMPrice(197.00);
stockGrabber.setAAPLPrice(677.60);
stockGrabber.setGOOGPrice(676.40);
// Create 3 threads using the Runnable interface
// GetTheStock implements Runnable, so it doesn't waste
// its one extendable class option
Runnable getIBM = new GetTheStock(stockGrabber, 2, "IBM", 197.00);
Runnable getAAPL = new GetTheStock(stockGrabber, 2, "AAPL", 677.60);
Runnable getGOOG = new GetTheStock(stockGrabber, 2, "GOOG", 676.40);
// Call for the code in run to execute
new Thread(getIBM).start();
new Thread(getAAPL).start();
new Thread(getGOOG).start();
}
}