Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that uses the following in Java : Observer Design Pattern Assignment This assignment will give you practice in using the Observer Design

Write a program that uses the following in Java :

Observer Design Pattern Assignment

This assignment will give you practice in using the Observer Design Pattern.

Consider a stock trading system whereby there is a stock market that keeps track of all trades of specific stocks (subjects) and must inform all traders (observers) when a new trade has been made for a certain stock. (Stocks are distinguished by short acronyms (i.e. MSFT, GOOG, AAPL) and a trade of a specific stock be either a buy or sell and it occurs at a certain price.) Each stock subject will maintain a list of all traders registered with it and will notify each registered trader when a trade has been made for that specific stock.

You may use either the Subject/Observer interfaces provided in the Observer lab or the observer pattern available in the Java API.

Design the Trader class (which implements either the Observer interface or java.util.Observer.)

Design the Stock class (which implements either the Subject interface or extends the java.util.Observable class.)

Write some test code that creates a StockMarket as well as 2-3 Stock objects. Furthermore, create 2-3 Trader objects. Have the stock market register each trader with a few stocks and then have the traders make trades for those stocks. (Remember trades are either a buy or sell and occur at a certain price.) Make sure your test code illustrates how each trader is notified when a trade for the stock(s) they are registered for is made.

You may find it helpful to model Trades of each stock similar to the Bid.java class.

This application is a little more involved than the Auction example from the lab.

Each stock will have its own list of observers. You will probably have to add the observers to each stock separately from their constructor. The output must have not only the traders name and amount, it must indicate the stock symbol and the transaction type (buy or sell).

Heres some sample output:

The latest trade is Trader: Julie sell $160.0 Stock: MSFT The latest trade is Trader: Julie sell $160.0 Stock: MSFT The latest trade is Trader: Amy sell $165.0 Stock: AAPL The latest trade is Trader: Amy sell $165.0 Stock: AAPL The latest trade is Trader: Julie buy $170.0 Stock: GOOG

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

2. What should an employer do when facing an OSHA inspection?

Answered: 1 week ago