Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use printf to ensure dollar values are rounded to two decimal places. JAVA The following program models an Investment Protfolio. Please follow the model as

Use printf to ensure dollar values are rounded to two decimal places. JAVA

The following program models an Investment Protfolio. Please follow the model as described.

There are many different kinds of investments, including stocks, bonds, and bank accounts.

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

b. Where did they come from?

Answered: 1 week ago

Question

c. What were the reasons for their move? Did they come voluntarily?

Answered: 1 week ago

Question

5. How do economic situations affect intergroup relations?

Answered: 1 week ago