Copyright  © – Sudharsan Iyengar

 

CS – 234.        Individual Programming Assignment: #3(a).             Due Date: Midnight 11/10/24

                                   

Write a Stock class. Declare the data members Symbol, volume, price as private.

 

It should have a constructor which requires a symbol (string), a volume (int), and a price (double). Other than the getters and setters, the following operational methods are required for the Stock class.

 

            Method Name Parameters                  Purpose of the method

 

            Buy                             number, new_price     decreases the volume by number and sets the stock-price to the new price

            Sell                              number, new_price     increases the volume by number and sets the stock-price to the new price

            toString                       none                            Returns a printable string with - volume and price, and total value of the stock

 

A stock is first offered to the public at a start-off stock-price. The initial offering also comes with an initial volume (or number of stocks). Every stock is identified by a stock symbol – which is a string. Then, the stock market takes over and the stock-price fluctuates with the buying and selling of the stock.

 

Write an application (call this class – Broker). The broker class acts as a buyer and seller of stock for ONE client. This application should

 

Request a symbol, an initial volume, and an initial price for a market stock from the user and create a Stock object with this information in it.

 

Output the current state of this Stock object.

 

Request the name of a client and their initial money.

 

Outputs the portfolio of the client - the name, the initial money held, and the number of stocks held (initially it would be 0).

 

            Then, it presents an option to buy or sell the stock – or to quit the application. Based on user response, request the user for the volume and the price for buying or selling. Then, if the user wants to buy – the buy method is called on the stock object using the volume and price chosen by the user. The broker adjusts the client portfolio – to reflect the money available and stock held.

 

            The above process is repeated - option to buy or sell or quit - is presented until the user chooses to quit.

           

The number of stocks bought cannot be more than the volume held in the stock; user cannot sell more than that which is held by the user; user cannot buy more than what the money available allows.

 

            Finally output the current state of the Stock, and the user portfolio.

 

Ex:                  User inputs the symbol “MYSTK” initial volume as 10000, and starting price as $ 8.00.

 

                        User inputs the client name as “Iyengar” and client’s money as $ 50000.

 

                        Output of Current State:

                                                                        Symbol                       MYSTK

                                                                        Volume                       10000

                                                                        Price                            $ 8.00

                                                                        Value                          $ 80000.00

 

                        User selects Buy

                                    User inputs                  Volume           1000   

                                                                        Price                8.25

 

                        User selects Sell

 

                                    User inputs                 Volume           500

                                                                        Price                8.50

 

                        Output of Current State:

                                                                        Symbol                       MYSTK

                                                                        Volume                       9500

                                                                        Price                            $ 8.50

                                                                        Value                          $ 80750.00

                        Stocks held by Broker:

                                                                        Client Name:              Iyengar

                                                                        Client Money              $ 46000

                                                                        Symbol                       MYSTK

                                                                        Volume                       500

                                                                        Price                            $ 8.50

                                                                        Value                          $ 4250.00

 

                                                                        Total Value:                $ 50250.00

 

The Stock Class and the Broker Application is Due before end of Sunday - 11/10/24: Store your project in your folder for this class.