Question: Implement a Stock class that has the following attributes: symbol (String), price (double), number of shares (int) and the following methods: Constructor (that sets the
Implement a Stock class that has the following attributes: symbol (String), price (double), number of shares (int) and the following methods: Constructor (that sets the symbol, price and number of shares to user defined values). Get and set methods. toString method returns the symbol, price and number of shares method public int compareTo(Stock s) compares the share price of this stock with another stock and returns: -1 if the value of this stock is lower than the other stock. 1 if the value of this stock is higher than the other stock. 0 if both the values are the same. (Value of the stock = price * number of shares) For example, lets say IBM has a price of $105.23 and you have bought 45 shares and MOS has a price of $89.88 and you have bought 60 shares. Then the value of IBM in your portfolio is 105.23*45= $4735.35 and the value of MOS in your portfolio is 89.88*60 = $5392.80. Comparing this stock(IBM) with another stock(MOS) will return a -1 since the value of MOS is greater in your portfolio. Test the Stock class with a client program that asks the user to enter the symbols, share prices, and number of shares for two stocks, prints their values, determines which stock is higher than the other and by how much and prints the total value. You must use the methods in the Stock class wherever appropriate. A portion of the client program is given below for your programming convenience.
FULL QUESTION IN IMAGES BELOW 

Exercise 3: Implement a Stock class that has the following attributes symbol (String), price (double), number of shares int) and the following methods Constructor (that sets the symbol, price and number of shares to user defined values) Get and set methods. toString method returns the symbol, price and number of shares method public int compareTo (Stock s) compares the share price of this stock with another stock and returns: -1 if the value of this stock is lower than the other stock. l if the value of this stock is higher than the other stock 0 if both the values are the same. alue of the stock -price number of shares For example, let's say IBM has a price of $105.23 and you have bought 45 shares and MOS has a price of $89.88 and you have bought 60 shares. Then the value of IBM in your portfolio is 105.23*45 $4735.35 and the value of MOS in your portfolio is 89.88*60 $5392.80. Comparing this stock(IBM) with another stock(MOS) will return a -1 since the value of MOS is greater in your portfolio Test the Stock class with a client program that asks the user to enter the symbols, share prices, and number of shares for two stocks, prints their values, determines which stock is higher than the other and by how much and prints the total value. You must use the methods in the Stock class wherever appropriate A portion of the client program is given below for your programming convenience. import ava util. Scanner public class StockDemo public static void main (String args) Scanner keyboard. new Scanner (System in) String syml sym2 i double prcl prc2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
