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

3. (21 points) Write a method that calculates and returns the value of an invest

ID: 3754797 • Letter: 3

Question

3. (21 points) Write a method that calculates and returns the value of an investment after a number of years, assuming that interest is compounded only at the end of each year. Your method will need the following parameters: The initial amount of money invested The interest rate The number of years you will be holding the investment You can use the formula value = investment * (1 + rate)years . You must include a Javadoc comment Name CSCI161-(01,02,03 Homework 03- Page 2 4. (19 points) Write a main method that would go in the same class as the previous method. It should read an initial investment amount and interest rate from the user. Then it should print a two-column table showing the number of years and final value for each year from 1-20. You do not need to include Javadoc comments. You may assume that the Scanner class has already been imported

Explanation / Answer

Below is your code. Please let me know if you have any issues: -

public class InvestmentTracker {

/**

* Method to calculate the return value

*

* @param amount

* - Initial Investment

* @param interestRate

* - Rate of Interest

* @param years

* - years invested

* @return total return value

*/

private static double getReturnValue(double amount, double interestRate, int years) {

return amount * Math.pow((1 + (interestRate/100.0)), years);

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the Investment Amount: ");

double amount = sc.nextDouble();

System.out.print("Enter the interest rate: ");

double intRate = sc.nextDouble();

System.out.println();

System.out.println("Year# Investment Value");

for (int i = 1; i <= 20; i++) {

System.out.println(i+" "+getReturnValue(amount, intRate, i));

}

sc.close();

}

}

Output

Enter the Investment Amount: 20000

Enter the interest rate: 10

Year# Investment Value

1 22000.0

2 24200.000000000004

3 26620.000000000007

4 29282.000000000007

5 32210.20000000001

6 35431.220000000016

7 38974.342000000026

8 42871.77620000003

9 47158.95382000004

10 51874.84920200005

11 57062.33412220005

12 62768.567534420064

13 69045.42428786207

14 75949.96671664828

15 83544.96338831313

16 91899.45972714444

17 101089.40569985891

18 111198.3462698448

19 122318.18089682929

20 134549.99898651222