Question: Encapsulate the Stock class below by making the fields private. Also add accessor methods named getSymbol, getTotalShares, and getTotalCost to return the stock's symbol, total
Encapsulate the Stock class below by making the fields private. Also add accessor methods named getSymbol, getTotalShares, and getTotalCost to return the stock's symbol, total shares, and total cost respectively.
Snow Heade ?BJP4 Self-Check 8.31: accessorsStock ? Favorite Language/Type: Java classes encapsulation instance methods Marty Stepp (on 2016/09/08) Author: Encapsulate the Stock class below by making the fields private. Also add accessor methods named getSymbol, getTotalShares, and getTotalCost to return the stock's symbol, total shares, and total cost respectively. ?Revert Type your solution here: 1 public class Stock 2String symbol; // stock symbol, e.g. "YHOO int totalShares; // total shares purchased double totalCost 4 public Stock (String theSymbol) { 6 7 if (theSymbol = null) { throw new NullPointerException 9 10 symbol = theSymbol; totalShares 0 totalCost-0.e 12 13 14 15 16 17 18 19 20 21 public double getProfit (double currentPrice) { if (currentPrice
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
