Question: Stock translate this into java code The attributes of Stocks are pricePerShare, numOfSharesOwned, and dividendsEarnedToDate (a percent of the investment paid annually), as well as
Stock translate this into java code
- The attributes of Stocks are pricePerShare, numOfSharesOwned, and dividendsEarnedToDate (a percent of the investment paid annually), as well as the inherited attributes. These pricePerShare and numOfSharesOwned have accessors and mutators.
- There is a default constructor that calls the super default constructor.
- There is a constructor with name (of the stock), pricePerShare and numSharesOwned.
- Calls super, hardcoding Stock for the type.
- Calls mutators for the pricePerShare and numSharesOwned parameters.
- Calls setInvestmentValue with the initial value of the investment as calculated from the other two parameters.
- There is also a method calcStockValues with parameters of type double priceChange and dividendPercent. (Note: Based on stock is called periodically)
- The pricePerShare increases or decreases by the priceChange (which could be positive or negative.
- The currentDividend is calculated by the pricePerShare*dividendPercent/100.0
- Increment the dividendsEarnedToDate as appropriate
- If there was a profit indicated in this call use the dividend to buy additional shares and update the numOfSharesOwned.
- Calculates the new total value of the investment and calls setInvestmentValue to set the value (It is simple to calculate new totalValue).
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
