Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please tell me how to make below StockExchange class and tester class (JAVA) (It would be helpful if you could include // comment on the

Please tell me how to make below StockExchange class and tester class (JAVA)

(It would be helpful if you could include // comment on the code.)

StockExchange Class

StockExchange class which stimulates an exchange with only one stock.

It communicates the changes in the stock price to a list of stock exchange customers.

  • The StockExchange class should maintain a list of objects that implement the StockObserver interface
  • communicate its changes to the observers using the method in the StockOvserver interface

The StockExchange has the following properties:

  • Instances have a method with signature public void tick(). which causes the stock exchange to move forward one unit of time
  • Stock price changes whenever the instance method tick() is called.
  • Stock price has a 50/50 probability of going up or down.
  • Has the AddObserver and RemoveObserver methods that allow observers that implement the following StockObserver interface to add and remove themselves

Use the following interface for StockObserver

public interface StockObserver{

public void priceChanged(PriceChangeEvent);

}

Need a PriceChangeEvent class that contains 2 fields

  • one for the change in price and another to the reference to the StockExchange object.
  • The StockExchange object will communicate the change in price to the registered classes that implement the StockObserver interface (observers) through a call-back using the priceChanged method in the interface.

These observer objects can use the information in the priceChangedEvent to determine the changes in the stock price and remove themselves from the exchange observer list when their target price is reach.

Need to make the following observer classes:

  • A StockMonitor class that implements StockObserver interface and monitors the changes in the stock price. The StockMonior should monitor and print how many steps it takes for the stock to change by a specific amount.
  • A StockPricePrinter class that implements the StockObserver interface and prints the stock price after each change in the stock price.

Tester Class

  • The Tester class should make an instance of the StockExchange class and 5 instance of the StockMonitor classes, each with a different target price. Also, Tester should make one instance of a StockPricePrinter class to monitor and plot the changes in price after each change in the price.
  • All 5 StockMonitors and the 1 StockPricePrinter should be "subscribed" to the StockExchange's notification list
  • Tester should repeatedly call the exchange's tick() method to run the simulation forward in time
  • The StockMonitor objects should remove themselves from the StockExchange when the stock prices reach its individual target price.
  • The program should stop when all StockMonitor objects have removed themselves.
  • The StockPricePrinter should keep plotting the price from the beginning to the end of the run

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Certainly Heres an example implementation of the described classes in Java java import javautilArray... 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

Financial Accounting

Authors: Robert Kemp, Jeffrey Waybright

2nd edition

978-0132771801, 9780132771580, 132771802, 132771586, 978-0133052152

More Books

Students also viewed these Programming questions