Write a program that takes two numbers from the Java console representing, respe
ID: 670617 • Letter: W
Question
Write a program that takes two numbers from the Java console representing, respectively, an investment and an interest rate (you will expect the user to enter a number such as .065 for the interest rate, representing a 6.5% interest rate). Your program should calculate and output (in $ notation) the future value of the investment in 5, 10, and 20 years using the following formula:
future value = investment * (1 + interest rate)^year
We will assume that the interest rate is an annual rate and is compounded annually.
Explanation / Answer
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class InvestmentCalculator
{
public static double getFutureValue(int investment,double interestRate,int year)
{
return Math.pow(investment*(1+interestRate),year);
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int investment;
double interestRate;
Scanner a = new Scanner(System.in);
System.out.println("Enter the investment amount : ");
investment = a.nextInt();
System.out.println("Enter the interest rate : " );
interestRate = a.nextDouble();
double futureValue = getFutureValue(investment,interestRate,5);
System.out.println("Future value after 5 years is : "+futureValue);
futureValue = getFutureValue(investment,interestRate,10);
System.out.println("Future value after 10 years is : "+futureValue);
futureValue = getFutureValue(investment,interestRate,20);
System.out.println("Future value after 20 years is : "+futureValue);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.