Question: C# PROGRAM In this lab assignment , you create an application that models the ups and downs of a particular stock. The value of a

C# PROGRAM

In this lab assignment , you create an application that models the ups and downs of a particular stock. The value of a stock is assumed to change by plus or minus a specified number of units after every time unit (such as one hour). A notification of selling stock is generated each time a stock changes more than a specified number of units above or below its intial value. A collection of customers who own the stock must receive this notification. The range within which the stock can change every time unit and the threshold above or below which collection of customers who own the stocks must be notified are specified when the stock is created (using its constructor).

You shall design and implement a C# application that satisfies the specification given above. This application involves delegates, events and threads. You begin by defining a delegate class StockNotification. This is shown below.

public delegate void StockNotification(String stockName, currentValue, initial value, stock quantity);

This delegate is designed so that when an event of this type is fired, the stock's name, current value, initial value, and stock quantity can be sent to the listener.

You are required to use Func or Action C# delegate.

Create the class Stock with the following attributes:

Stock name

Stock intial value

Stock quantity

Maximum change (the range within a stock can change every time unit)

Notification threshold (the threshold above or below which the collection of customers who own the stock must be notified)

You are required to implement other members in the class Stock that are needed. When a stock object is created, a thread is started. This thread causes the stock's value to be modified every 500 milliseconds. If its value changes from its initial value by more than the specified notification threshold, an event method is invoked. This invokes the stockEvent (of event-type StockNotification) and multicasts a notification to all listeners who have registered with stockEvent.

Create another event to notify saving the following information to a file when the stock's threshold is reached: date and time, stock name, inital value, current value, and amount of loss or gain.

Create the class StockCustomer which has fields customer name and stocks, a list of Stock. This latter field is not used in this application but could be used to obtain the stocks currently owned by a given customer. The addStock method registers the Notify listerner with the stock (in addition to adding it to the list of stocks held by the customer). This Notify method outputs to the console the customer name, the intial value, and the current value, amount of loss or gain. .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!