nconpabblity Mode) Word ayout References Mailings Review View Tell me what you w
ID: 3722632 • Letter: N
Question
nconpabblity Mode) Word ayout References Mailings Review View Tell me what you want to do | A·.A- $-a-m. | 1Normal 1N0 Spac Heading 1 Heading 2 Title Paragraph Styles 1. Calculating Future Investment Value Problem Description: Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value using the following formula: and displays the future investment value using the following formula: future! nvestmentvalue = be on ears. investmentAmount * (1+ monthlyInterestRaton For example, if you enter amount 1000, annual interest rate 3.25%, and number ofyears , the future investment value is 1032.98. Hint: Use the Math pow(a, b) method to compute a raised to the power of b. Here is a sample run: Sample 1: Enter investment amount: 1000 Enter annual interest rate: 4.25 Enter number of years: 1 Accumulated value is 1043.34 Sample 2: Enter investment amount: 1000 Enter annual interest rate: Enter number of years : 1Explanation / Answer
import java.io.*;
import java.util.*;
public class invest
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
double investAmount,interest,finalValue,monthlyInterest,temp,a;
int years,b;
System.out.println("Enter investment amount: ");
investAmount=sc.nextDouble();
System.out.println("Enter annual interest rate: ");
interest=sc.nextDouble();
System.out.println("Enter number of years: ");
years=sc.nextInt();
monthlyInterest=interest/12;
a=monthlyInterest+1;
b=years*12;
temp=Math.pow(a,b);
finalValue=investAmount*temp;
System.out.println("Accumulated value is "+finalValue);
}
}
I think that there is somthing wrong with the formula as it is not giving the expected result
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.