Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA) Please solve this. I need output too. Thank you A. Write a StockExchange class that manages only one stock and communicates the changes in

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

JAVA) Please solve this. I need output too. Thank you

A. Write a StockExchange class that manages only one stock and 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 and communicate its changes to the observers using the method in the StockObserver interface. The StockExchange has the following properties: Stock price changes by one unit price once per second. You can use the Thread.sleep (1000) to make the current thread sleep for 1000 milliseconds (or make it an event-driven class using a Timer object). 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. interface StockObserver void pricedChanged (PriceChange Event); } You will need a PriceChange Event class that contains two 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 interfaces (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. Create the following observer classes: A StockMonitor class that implements StockObserver interface and monitors the changes in the stock price. The StockMonitor 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. Since there are many common characteristics between the StockMonitor and StockPricePrinter create a class StockCustomer that contains the common characteristics and derive the StockMonitor and StockPricePrinter from the StockCustomer class. Create a Tester class. The tester class should create an instance of StockExchange class and five instances of the StockMonitor classes, one each to monitor how many steps it takes the stock price to change by 5, 10, 15, 20, and 25 units up or down. Also, create one instance of a StockPricePrinter class to monitor and plot the changes in price after each change in the price. The StockMonitor objects should remove themselves from the StockExchange when the stock prices reaches its individual threshold. The program should stop when all StockMonitor objects have removed themselves and print the results observed by each monitor. The StockPricePrinter should keep plotting the price from the beginning to the end of the run. A. Write a StockExchange class that manages only one stock and 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 and communicate its changes to the observers using the method in the StockObserver interface. The StockExchange has the following properties: Stock price changes by one unit price once per second. You can use the Thread.sleep (1000) to make the current thread sleep for 1000 milliseconds (or make it an event-driven class using a Timer object). 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. interface StockObserver void pricedChanged (PriceChange Event); } You will need a PriceChange Event class that contains two 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 interfaces (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. Create the following observer classes: A StockMonitor class that implements StockObserver interface and monitors the changes in the stock price. The StockMonitor 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. Since there are many common characteristics between the StockMonitor and StockPricePrinter create a class StockCustomer that contains the common characteristics and derive the StockMonitor and StockPricePrinter from the StockCustomer class. Create a Tester class. The tester class should create an instance of StockExchange class and five instances of the StockMonitor classes, one each to monitor how many steps it takes the stock price to change by 5, 10, 15, 20, and 25 units up or down. Also, create one instance of a StockPricePrinter class to monitor and plot the changes in price after each change in the price. The StockMonitor objects should remove themselves from the StockExchange when the stock prices reaches its individual threshold. The program should stop when all StockMonitor objects have removed themselves and print the results observed by each monitor. 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

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

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions