In: Computer Science
Write a program that reads three values from the keyboard representing, respectively, an investors name, an investment amount, 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 currency notation) the future value of the investment in 10, 2 20 an 30 years using the following formula: Future value =investment(1+interest rate)year
Example of a test run:
Enter NameSue Smith
Enter Investment Amount : 100.00
Enter Interest Rate : 065
Sue Smith , your future value in 10 years is $ 187.71
//create a class with name InvestCalculator.java and paste the
code given below
import java.util.Scanner;
public class InvestCalculator {
public static void main(String[] args) {
//get input from user
System.out.print("Enter name :");
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
System.out.println("");
System.out.print("Enter Investment Amount :");
double amount = sc.nextDouble();
System.out.println("");
System.out.print("Enter Interest Rate :");
//interest rate should be in format of .065
double rate = sc.nextDouble();
//formula for investment calculator
double future_value_10 = amount * Math.pow((1 + rate), 10);
double future_value_20 = amount * Math.pow((1 + rate), 20);
double future_value_30 = amount * Math.pow((1 + rate), 30);
System.out.println(name + ", your future value in 10 years is $" +
String.format("%.2f", future_value_10));
System.out.println(name + ", your future value in 20 years is $" +
String.format("%.2f", future_value_20));
System.out.println(name + ", your future value in 30 years is $" +
String.format("%.2f", future_value_30));
}
}
//output
Enter name :Sue Smith
Enter Investment Amount :100.00
Enter Interest Rate :.065
Sue Smith, your future value in 10 years is $187.71
Sue Smith, your future value in 20 years is $352.36
Sue Smith, your future value in 30 years is $661.44