StockHoldingjava Please help me the JAVA program Write a cla
StockHolding.java
Please help me the JAVA program
Write a class StockHolding. The purpose of a StockHolding object is to represent a single stock in someone\'s investment portfolio. The StockHolding class has the following specification:
 Write a class StockHoldingMain that contains a main method. The main method should create three StockHolding objects. For each object, print the initial cost, set the current share price, print the current profit, and print the toString value. The following is sample output from a main method creating a StockHolding for 19 shares of Apple at $103.97 and a current price of 105.5:
Solution
public class StockHolding {
   String ticker;
    int shares;
    double initialSharePrice;
    double currentSharePrice;
public StockHolding(String ticker, int numberShares, double initialPrice) {
       this.ticker = ticker;
        this.shares = numberShares;
        this.initialSharePrice = initialPrice;
        this.currentSharePrice = initialPrice;
}
   public void setCurrentSharePrice(double sharePrice) {
        this.currentSharePrice = sharePrice;
}
public String getTicker() {
       return ticker;
    }
   public int getShares() {
        return shares;
    }
   public double getInitialSharePrice() {
        return initialSharePrice;
    }
   public double getCurrentSharePrice() {
        return this.currentSharePrice;
    }
   // number of shares * initial price
    public double getInitialCost() {
        return shares * initialSharePrice;
    }
   // number of shares * current price
    public double getCurrentValue() {
        return shares * currentSharePrice;
    }
   // number of shares * (current price - initial price)
    public double getCurrentProfit() {
       return shares * (currentSharePrice - initialSharePrice);
    }
   // returns \"stock <ticker>, <number of shares> shares bought at <initial
    // price>, current price <current price>
    public String toString() {
        return \"Stock \" + ticker + \", \" + shares + \", shares bought at \"
                + initialSharePrice + \", current price \" + currentSharePrice;
    }
 }
 public class StockHoldingMain {
public static void main(String[] args) {
       StockHolding holding = new StockHolding(\"AAPL\", 19, 103.97);
        holding.setCurrentSharePrice(105.5);
        System.out.println(\"apple initial cost: \" + holding.getInitialCost());
        System.out.println(\"apple profit: \" + holding.getCurrentProfit());
        System.out.println(holding);
    }
 }
OUTPUT:
apple initial cost: 1975.43
 apple profit: 29.07000000000002
 Stock AAPL, 19, shares bought at 103.97, current price 105.5


