Answer to Question #255968 in Java | JSP | JSF for RaselNeel

Question #255968

Q1. Write a Java method to compute the future investment value at a given interest rate for a 

specified number of years.

Input the investment amount: 1000 

Input the rate of interest: 10 

Input number of years: 5 

Years FutureValue 

1 1104.71 

2 1220.39 

3 1348.18 

4 1489.35 

5 1645.31


1
Expert's answer
2021-10-24T13:53:43-0400
import java.util.Scanner;
public class Main {
 
 public static void main(String[] args) {
    Scanner in = new Scanner(System.in); 
    System.out.print("Input the investment amount: ");
 	double investment = in.nextDouble();
 	System.out.print("Input the rate of interest: ");
	double rate = in.nextDouble();
	System.out.print("Input number of years: ");
	int year = in.nextInt();
	
	rate *= 0.01;
	
	System.out.println("Years    FutureValue");
	for(int i = 1; i <= year; i++) {
    	int formatter = 19;
	    if (i >= 10) formatter = 18;
		System.out.printf(i + "%"+formatter+".2f\n", futureInvestmentValue(investment, rate/12, i));
       }
	 }
 
 public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years) {
		return investmentAmount * Math.pow(1 + monthlyInterestRate, years * 12);
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS