Question: I want to translate this into code java language Investment Design an abstract Investment class that includes String type and String name attributes, and a
I want to translate this into code java language
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 (found in the homework).
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 (found in the homework)
BankAccount
- BankAccount is an abstract class that extends Investment. The name field holds the banks name. An additional String attribute accountNumber represents an account number. It also has the inherited attributes. This attribute has a mutator and an accessor. BankAccount has two subclasses: SavingsAccount and CheckingAccount.
- There is a default constructor that calls the super default constructor. It also uses a mutator to set the accountNumber to none.
- There is a constructor with type, name and accountNumber.
- Calls super with type and name
- Call mutator to set the accountNumber.
- There is a toString method that uses super.toString to help print out the BankAccount data
SavingsAccount
- A SavingsAccount is a sublass of a BankAccount. SavingsAccount has annualInterestRatePercent, rate(the prior value divided by 12 and by 100) and totalInterestEarned as instance variables as type double, as well as the inherited instance variables. Both annualInterestRatePercent and totalInterestEarned have accessors and mutators. The setAnnualInterestRatePercent method also calculates the rate of return (divide by100.0)
- There is a default constructor that calls the super default constructor.
- There is a constructor with name and accountNumber, the initialDeposit, and the annualInterestRatePercent.
- Call super with "SavingsAccount", bankName, and accountNumber.
- Call setInvestmentValue to the initialDeposit.
- Call setAnnualInterestRatePercent with the annualInterestRatePercent.
- There is a method makeDeposit with a double deposit input parameter that uses setInvestmentValue to update the amount in the account.
- There is a method makeWithdrawal with a double withdrawal input parameter that checks if there are sufficient funds to withdraw. If there arent dont make a withdrawal but print a message stating insufficient funds. Otherwise uses setInvestmentValue to update the amount in the account. This method returns true if withdrawal is made, otherwise false
- There is a method calcValue with no parameters which calculates the interest for the month (assume a monthly interest payment so divide rate by 12).
- Then add to totalInterestEarned the interest calculated
- Call setInvestmentValue which adds the interest the investmentValue (so that interest is collected on the entire amount).
- There is a toString method that uses super.toString to help print out the SavingsAccount data
CheckingAccount
- A CheckingAccount is a subclass of a BankAccount with a minimum balance for free checking, and an annual interest rate (paid monthly) on all the money if the minimum balance is met, and a charge per check if the minimum balance isnt met.
- CheckingAccount includes type double instance variables annualInterestRatePercentage, rate, totalInterestEarned, minimumCheckFreeBalance, checkCharge and totalCheckCharges, as well as the inherited instance variables. Each of annualInterestRatePercentage, totalInterestEarned, minimumCheckFreeBalance, checkCharge and totalCheckCharges have accessors and mutators. The setAnnualInterestRatePercent method also calculates the associated rate of return (divide 100.0)
- There is a default constructor that calls the super default constructor.
- There is a constructor with name and accountNumber, and the initialDeposit, annualInterestRatePercentage, minimumCheckFreeBalance and checkCharge.
- Call super with "CheckingAccount", bankName, accountNumber.
- Call setInvestmentValue to the initialDeposit.
- Call setMinimumCheckFreeBalance.
- Call setCheckCharge.
- There is a method makeDeposit with a double deposit input parameter that uses setInvestmentValue to update the amount in the account.
- There is a method writeCheck with a double checkValue
- If there is not enough in the account to cover the check, print a message to the terminal indicating insufficient funds and return false.
- If the investmentValue >= the minimumCheckFreeBalance
Update the investment value by deducting the check value
else
Update the investment value by deducting the check value and the check charge
Update totalCheckCharges
Return true
- There is a method calcValue with no parameters (we are assuming a monthly update)
- If the investmentValue >= minimumCheckFreeBalance
- Calculate this months interest based on a monthly rate (divide rate by 12).
- Adds interest to the totalInterestEarned
- Updates the investmentValue
- If the investmentValue >= minimumCheckFreeBalance
- There is a toString method that uses super.toString to help print out the SavingsAccount data
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
