Copyright  ©Sudharsan Iyengar

 

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

                                   

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 a Stock class. It should have a constructor which requires a stock symbol (string), an initial volume (int), and an initial stock-price (double). Other than the getters and setters, the operational methods required for the Stock class are –

 

            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

 

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

 

Request a symbol, initial volume, and start off price for one 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 client and their initial money.

 

Outputs the portfolio of the client - the name, the initial money held, and the number of stocks held.

 

            Then, it presents an option to buy the stock. Based on user response, for volume and price – the stock is bought for the user. The

            broker adjusts the client portfolio.

 

            Then, it presents an option to sell the stock. Based on user response, for volume and price – the stock is sold for the user.  The broker adjusts the

client portfolio.

 

            (Note that the number of stocks bought cannot be more than the initial volume; and cannot sell more than that has been bought)

 

            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 Midnight Wednesday - 10/31/12: Store your project in your folder for this class.