Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please do stock and bond only I am having some issues with them. java Investment Design an abstract Investment class that includes String type and
please do stock and bond only I am having some issues with them. java
Investment
- Design an abstract Investment class that includes String type and String name attributes, and a double investmentValue attribute. Each has an accessor and mutator method. There is also a toString method to print out the type and the name.
- There is a default constructor that sets the type and name to none.
- There is also a two parameter constructor with the type and name. The Investment class, being abstract, cannot be instantiated.
- There is also a toString method to print out the type and the name.
- Stock :
- 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).
- There is a toString method that uses super.toString to help print out the stock data in accord with the portfolioresults.txt file
Bond
- The attributes of Bond are double pricePerBond, annualReturnPercentage, rate, cashEarnedToDate, and int numBondsOwned, as well as the inherited attributes. There are accessors and mutators for pricePerBond, numBondsOwned, and annualReturnPercentage. The setAnnualReturnPercentage method also calculates the monthly rate of return (divide by 12. And 100.)
- There is a default constructor that calls the super default constructor.
- There is a constructor with name (of the bond), pricePerBond, numBondsOwned, and annualReturnPercentage.
- Calls super, hardcoding Bond for the type.
- Calls mutators for the pricePerBond, numSharesOwned and annualReturnPercentage parameters.
- Calculates the new total value of the investment and calls setInvestmentValue to set the value (It is simple to calculate new totalValue)
- There is a method calcBondValues with no parameters that assumes that it is being called on a monthly basis (for simplicity)
- Calculates cashEarnedToDate by adding to the current cashEarnedToDate the value of one months worth of interest based on pricePerBond
- Call setInvestmentValue as pricePerBond*numBondsOwned + cashEarnedToDate. (Note we arent reinvesting here like we did for Stock)
- There is a toString method that uses super.toString to help print out the bond data in accord with the portfolioresults.txt file
-
portfolioresults.txt: Investment: Stock Name: Google Price Per Share: $1,136.65 Number Of Shares: 425.44 Current Value: $483,578.26 Investment Earnings to date: 405,481.50 Investment: Bond Name: CALMUNI Price Per Bond: $34.77 Number Of Bonds: 100 Current Value: $4,259.33 Cash On Hand To Date: $782.33
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started