Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

------JAVA------ Prompt the user to enter an investment amount and store it as a

ID: 665149 • Letter: #

Question

------JAVA------

Prompt the user to enter an investment amount and store it as a double variable called investmentAmount. Prompt the user to enter a yearly interest rate and store it as a double called annualInterestRate. Output table headers "Years" and "Future Value". Format "Years" as a string, left aligned, in a column of at least 5 chars. Format "Future Value" as a string, right aligned, in a column of at least 20 chars.

Create a for loop that loops 30 times. In the for loop create a double called futureValue and assign it the value of futureInvestmentValue. futireInvestmentValue will pass investmentAmount, annualInterestRate / 1200 and i.

Print i and futureValue in a table with i formatted as a string, left aligned, in a column of at least 5 chars and with futureValue formatted as a string, right aligned, in a column of at least 20 chars.

Create a method called futureInvestmentValue of type double that takes three inputs: double investmentAmount, double monthlyInterestRate, and int years. The function will return investmentAmount times 1 + monthlyInterestRate to the power of years times 12.

Explanation / Answer

import java.util.*;
import java.math.*;

public class calcInvestment
{
    public double futureInvestmentValue(double Amount, double roi, int yrs)
    {
        return (Amount * pow((1 + roi),12*yrs));
    }
    public static void main(String args[])
    {
        double investmentAmount, annualInterestRate;
        System.out.println("Please enter the investment amount");
        Scanner inv_amt=new Scanner(System.in);
        investmentAmount=inv_amt.nextDouble();
        System.out.println(investmentAmount);
        System.out.println("Please enter yearly interest rate");
        annualInterestRate=inv_amt.nextDouble();
        System.out.println(annualInterestRate);
        String head1 = "Years";
        String head2 = "Future Value";
        System.out.printf( "%-5s %20s %n", head1, head2);
        int i;
        for(i=1;i<=30;i++)
        {
            double futureValue;
            futureValue=futureInvestmentValue(double investmentAmount, double annualInterestRate,int years);
            System.out.printf( "%-5s %20s %n", years, futureValue);
           
        }

    }  
}