Copyright  © – Sudharsan Iyengar

 

CS – 234.                    Individual Programming Assignment: #3(b).

 

Modify the Stock class (from 3(a)) to handle the following:

 

            Allows buys if and only if the new price is within 5% of the current price.

            Allows sells if and only if the new price is within 5% of the current price.

 

If a buy, or sell, request is improper, a Boolean false is returned by the methods. Else the method returns true, and the buy/sell is executed.

 

A new Customer class is defined that holds the following information.

 

                        Customer Name          a String

Balance                       a double value

Portfolio                     Four (4) stocks that is held on behalf of the customer

 

            Methods on this class are

 

                        Constructor                 takes in Customer name, starting balance, and an empty portfolio

                        getBalance                  returns the current balance with the customer

                        SuccessfulBuy takes in Stock name, shares bought, amount spent; and changes the portfolio and balance

                        SuccessfulSell takes in Stock name, shares sold, amount returned; and changes the portfolio and balance

                        toString                       returns a printable string with the User name, Account Balance, and Portfolio.

 

            (Remember customer can buy only if there is enough money for the transaction and can only sell from his/her portfolio)

 

The Application – the Broker class – is modified to do the following:

 

            Create and manage 4 stocks which are initialized as follows:

 

                        Stock name     init volume     init price

 

                        “STK1”                       10000              $ 8.00

                        “STK2”                       20000              $ 5.00

                        “STK3”                       10000              $ 9.00

                        “STK4”                       30000              $ 10.00

 

            Create and manage 3 Customer accounts, initialized as follows.

 

                        Customer Name          Starting Account Balance

 

                        “C1”                            $ 100000.00                           

                        “C2”                            $ 25000.00

                        “C3”                            $ 50000.00

 

            All the three customers have empty portfolio. After the transactions they can have any of the four stocks indicated above.

 

            These initial information on the stock and customer information are not obtained from the user. These are not constants either. They are initial values provided.

 

            First – display all stocks and their current state. Then, display all the customers and their portfolio.

 

            Then gives a menu option to select a customer, or exit the application.

                        If a customer is selected – then give another option to perform trade or view-portfolio:

                                    If the view-portfolio option is selected – display the customer portfolio

                                    If a trade option is selected then provide another menu to buy or sell

                                                Then provide a menu to select a stock (to buy or sell)

                                                             Execute this trade.

                                                                        If the trade is executed successfully, then an appropriate message is output

and the resulting customer portfolio is displayed

                                                                        Else – output a message that the trade was not successful.

           

            The above process is repeated until the exit application option is selected.

 

            Finally,

 

                        Display the current state of all the stocks.

 

                        Display all the customers and their current portfolio.

 

Store your project with the updated Stock class, the Customer class, and the updated Broker Application: Due Date: Midnight - 11/25/24