COP4814 Assignment 3 (80 Points in total) Stock Price Observer (75 points) Using a stock portfolio model, design interfaces and classes that implement the Observer Pattern. Be sure to read Chapter 2 in Head-First Design Patterns first. A typical stock portfolio contains a collection of investments, and online brokerages let you view your investments in an application that periodically updates the display to reflect changing stock prices. Your program will write to standard output. You will probably need to build the program in steps 1. Create an Observer interface with a method that receives a Map of ticker symbols and prices 2. Copy the Subject and DisplayElement interfaces from Chapter 2 with no changes 3. Create a PriceData class that is more or less like the WeatherData class in Chapter 2 Rather than containing temperature, humidity, and pressure, this class should contain a Map of ticker symbols and stock prices. Make other changes to the class that seem appropriate Create a PricesDisplay class that implements the Observer and DisplayElement interfaces. PricesDisplay contains a list of ticker symbols (as strings). It is much like the CurrentConditionsDisplay class from Chapter 2. Its Display method should display each ticker symbol and price for each stock in its list of stocks. To do this, it will need to get the prices from the prices map. This class operates as your logical stock portfolio meaning that you will not define an actual Portfolio class Download and use the StockObserverTest class from my faculty website http://users.cis.fiu.edu/-crahn/ which creates the necessary objects and simulates the changes in stock prices. Each time it changes the prices, it calls a method in the PriceData class that broadcasts the new prices to all observer objects. The program’s output will resemble the following, where the two observer objects (one for each portfolio) have received a series of stock price updates and displays the information on the screen in pairs with a blank line between them as follows 4. 5. Portfolio #00001, ASD = 42.50, ADM= 45.00, AAC 22.20, AFAS = 52.50 Portfolio #00002, BSD = 42 . 50, BDM = 45 . 00, BAC = 22 . 20, BFAS = 52 . 50 Portfolio #00001, ASD = 43.50, ADM- 44.00, AAC 25.20, AFAS 55.50 Portfolio #00002, BSD = 41.00, BDM= 42.00, BAC 19.20, BEAS = 47.50 (etc.) Each portfolio contains a different list of stocks Submit a ZIP file called FirstnameLastnameA3.zip containing only Java source files. Please include a copy of my StockObserverTest.java file in the submission, but do not make any changes to it. Do not use the package statement in any of your files. Each class should be in a separate file. I will compile and run from the command line . There should be no other files or folders even if you are a Mac User. (5 points)

PROGRAM CODE:
PriceData.java
package stocks;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class PriceData implements Subject{
private Map prices;
private ArrayList observers;
public PriceData() {
prices = new HashMap();
observers = new ArrayList();
}
public void pricesChanged()
{
notifyObserver();
}
@Override
public void registerObserver(Observer o) {
observers.add(o);
}
@Override
public void removeObserver(Observer o) {
int i= observers.indexOf(o);
if(i>=0)
observers.remove(i);
}
@Override
public void notifyObserver() {
for(int i=0; i newPrices)
{
this.prices = newPrices;
pricesChanged();
}
public Map getPrices()
{
return prices;
}
}
PricesDisplay.java
package stocks;
import java.util.HashMap;
import java.util.Map;
public class PricesDisplay implements Observer, DisplayElement{
private String tickerSymbols[];
private String portfolio;
private Subject priceData;
private Map prices;
public PricesDisplay(String portfolio, PriceData pricedata)
{
this.portfolio = portfolio;
this.priceData = pricedata;
prices = new HashMap();
priceData.registerObserver(this);
}
@Override
public void display() {
System.out.print(“Portfolio #” + portfolio + “, “);
for(int i=0; i prices) {
this.prices = prices;
display();
}
public void setStocks(String[] strings) {
this.tickerSymbols = strings;
}
}
Observer.java
package stocks;
import java.util.Map;
public interface Observer {
public void update(Map priceData);
}
Subject.java
package stocks;
public interface Subject {
public void registerObserver(Observer o);
public void removeObserver(Observer o);
public void notifyObserver();
}
DisplayElement.java
package stocks;
public interface DisplayElement {
public void display();
}
OUTPUT:
Portfolio #00001, ASD = 42.5, ADM = 52.5, AAC = 22.2, AFAS = 45.0,
Portfolio #00002, BSD = 47.5, BDM = 21.5, BAC = 32.2, BFAS = 44.0,
Portfolio #00001, ASD = 43.35, ADM = 53.550000000000004, AAC = 22.644, AFAS = 45.9,
Portfolio #00002, BSD = 48.45, BDM = 21.93, BAC = 32.844, BFAS = 44.88,
Portfolio #00001, ASD = 41.1825, ADM = 50.8725, AAC = 21.511799999999997, AFAS = 43.605,
Portfolio #00002, BSD = 46.0275, BDM = 20.833499999999997, BAC = 31.2018, BFAS = 42.636,
Portfolio #00001, ASD = 43.65345, ADM = 53.924850000000006, AAC = 22.802508, AFAS = 46.2213,
Portfolio #00002, BSD = 48.78915000000001, BDM = 22.083509999999997, BAC = 33.073908, BFAS = 45.194160000000004,
Portfolio #00001, ASD = 44.9630535, ADM = 55.54259550000001, AAC = 23.48658324, AFAS = 47.607939,
Portfolio #00002, BSD = 50.25282450000001, BDM = 22.746015299999996, BAC = 34.066125240000005, BFAS = 46.549984800000004,
 
“Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!”

What Students Are Saying About Us

.......... Customer ID: 12*** | Rating: ⭐⭐⭐⭐⭐
"Honestly, I was afraid to send my paper to you, but splendidwritings.com proved they are a trustworthy service. My essay was done in less than a day, and I received a brilliant piece. I didn’t even believe it was my essay at first 🙂 Great job, thank you!"

.......... Customer ID: 14***| Rating: ⭐⭐⭐⭐⭐
"The company has some nice prices and good content. I ordered a term paper here and got a very good one. I'll keep ordering from this website."

"Order a Custom Paper on Similar Assignment! No Plagiarism! Enjoy 20% Discount"