Question: import java.util.Scanner; public class StockDemo { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String sym1, sym2; double prc1, prc2; int sh1,
![import java.util.Scanner; public class StockDemo { public static void main(String[] args)](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66ef34a94ea2a_61666ef34a8c8ce2.jpg)
import java.util.Scanner;
public class StockDemo
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String sym1, sym2;
double prc1, prc2;
int sh1, sh2;
//get the values for two stocks
System.out.print("Enter the symbols for the two stocks: ");
sym1 = keyboard.next();
sym2 = keyboard.next();
System.out.print("Enter their prices: ");
prc1 = keyboard.nextDouble();
prc2 = keyboard.nextDouble();
System.out.print("Enter the number of shares for the two stocks: ");
sh1 = keyboard.nextInt();
sh2 = keyboard.nextInt();
//create the first Stock
Stock s1 = new Stock(sym1,prc1,sh1);
//create the second Stock
Stock s2 = new Stock(sym2,prc2,sh2);
// continue the rest of the code here
The following is a sample screen dialog:
Enter the symbols for the two stocks: IBM MOS
Enter their prices: 105.23 89.88
Enter the number of shares for the two stocks: 45 60
I have the following stocks:
Stock: IBM
Price: 105.23
Shares: 45
Stock: MOS
Price: 89.88
Shares: 60
The value of MOS is higher than IBM by $ 657.45
The total value of my portfolio is $ 10,128.15
Process completed.
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 in a nice format- method compare (Stock returns: s) compares the share price of this stock with another stock and 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.J (Value 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 (demo class) 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
