Sure, I can help you with that. Here's a step-by-step guide on how to write the program you described:
Step 1: Import the required package for user input:
```java
import java.util.Scanner;
```
Step 2: Create a new Scanner object to read input from the console:
```java
Scanner scanner = new Scanner(System.in);
```
Step 3: Prompt the user to enter the investment amount and interest rate:
```java
System.out.print("Enter the investment amount: ");
double investment = scanner.nextDouble();
System.out.print("Enter the annual interest rate (in decimal form, e.g., 0.065): ");
double interestRate = scanner.nextDouble();
```
Step 4: Calculate and display the future value for 5, 10, and 20 years:
```java
int[] years = { 5, 10, 20 };
for (int i = 0; i < years.length; i++) {
int year = years[i];
double futureValue = investment * Math.pow(1 + interestRate, year);
System.out.println("Future value after " + year + " years: " + futureValue);
}
```
Step 5: Close the Scanner:
```java
scanner.close();
```
Putting it all together, here's the complete code:
```java
import java.util.Scanner;
public class FutureValueCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the investment amount: ");
double investment = scanner.nextDouble();
System.out.print("Enter the annual interest rate (in decimal form, e.g., 0.065): ");
double interestRate = scanner.nextDouble();
int[] years = { 5, 10, 20 };
for (int i = 0; i < years.length; i++) {
int year = years[i];
double futureValue = investment * Math.pow(1 + interestRate, year);
System.out.println("Future value after " + year + " years: " + futureValue);
}
scanner.close();
}
}
```
You can now run this program, enter the investment amount and interest rate when prompted, and it will calculate and display the future value for 5, 10, and 20 years.