Write a class encapsulating the concept of an investment, assuming
that the investment has the following attributes: the name of the
investor, the amount of the investment, and the static interest rate at
which the investment will be compounded. Include a default
constructor, an overloaded constructor, the accessors and mutators,
and methods, toString() and equals(). Also include a method returning
the future value of the investment depending on how many years
(parameter to this method) we hold it before selling it, which can be
calculated using the formula:
Future value = investment(1 + interest rate )year
We will assume that the interest rate is compounded annually. Write a
client class to test all the methods in your class and print out the tuture
value of and investment for 5, 10, and 20 years.

Respuesta :

A class encapsulating the concept of an investment, assuming that the investment has the following attributes is given below:

The Program

import java.util.Scanner;

   /**

      This program compares CD /Investment plans input by the year

      broken down by the requirements below:

      This program creates a table of compound interest investment growth over time

      Broken down by: a) year b) balance at end of year

      Finance formula of A= P(1+ r/n)^n*t is used:

      A = Future Value         | P = Initial Investment

      r = annual interest rate |n = times interest is compounded/year

      t = years invested

   */

    public class InvestmentTableFirstTest

    {

       public static void main(String[] args)

       {

            Scanner in = new Scanner(System.in);

            String bestBankName = "";

            double bestGrowth = 0;

            boolean done = false;

            while(!done)

            {

                System.out.print("Plan name (one word, Q to quit): ");

                String bankName = in.next();

                if (bankName.equals("Q"))

                {

                      done = true;

                }

                else

                {

                     System.out.print("Please enter your principal investment: ");

                     final double PRINCIPAL_INVESTMENT = in.nextDouble();

                     System.out.print("Please enter the annual interest rate: ");

                     double iRate = in.nextDouble();

                     System.out.print("Please enter number of times interest is compounded per year:  ");

                     final double INCREMENT = in.nextDouble();      

                     System.out.print("Enter number of years: ");

                     int nyears = in.nextInt();

                     iRate = iRate/100; System.out.println("iRate:" + iRate);

                     //Print the table of balances for each year

                      for (int year = 1; year <= nyears; year++)

                      {

                       double MULTIPLIER = INCREMENT * year;

                       System.out.println("Multiplier: " + MULTIPLIER); // I've included this print statement to show that the multiplier changes with each passing year

                       double interest = 1 + (iRate/INCREMENT);

                       double balance = PRINCIPAL_INVESTMENT;

                       double growth =  balance * Math.pow(interest, MULTIPLIER);

                       growth = growth - PRINCIPAL_INVESTMENT;                      

                       balance = balance + growth;                                  

                       System.out.printf("Year: %2d  Interest Earned:   $%.2f\t   Ending Balance:   $%.2f\n", year, growth, balance);

                      if (bestBankName.equals("") || bestGrowth > growth) // || bestBankName > growth

                      {

                           bestBankName = bankName;  // bestBankName = bankName

                           bestGrowth = growth; // mostGrow = growth

                      }

                         System.out.println("Earning with this option: " + growth);        

                 }

            }

        }

           System.out.println("Best Growth: " + bestBankName);

           System.out.println("Amount Earned: " + bestGrowth);      

      }

   }

Read more about programming here:

https://brainly.com/question/23275071

#SPJ1