Ask Question
20 September, 13:36

Write a program that takes two numbers from the Java console representing, respectively, an investment 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 $ notation) the future value of the investment in 5, 10, and 20 years using the following formula:

future value = investment * (1 + interest rate) ^year

We will assume that the interest rate is an annual rate and is compounded annually.

+5
Answers (1)
  1. 20 September, 15:36
    0
    in this case you have to use a For cycle

    Explanation:

    This is the entire code for this program

    Step 1: We declare two variables investment and interest with double, and we take the numbers with the console.

    We ask with console the two numbers

    We show the two number in console

    Step 2: We create two new double variable: Value and cont5

    We save the formula in the variable Value

    We create 3 For cycle

    the first one for 5 years

    the second one for 10 years

    the third one for 20 years

    package javaapplication6;

    import java. util.*;

    public class JavaApplication6 {

    /**

    * @param args the command line arguments

    */

    public static void main (String[] args) {

    / / TODO code application logic here

    double investment;

    double interest;

    Scanner keyboard = new Scanner (System. in);

    System. out. println ("Enter the investment");

    investment = keyboard. nextDouble ();

    System. out. println ("Enter the interest");

    interest = keyboard. nextDouble ();

    System. out. println ("With an investment of $"+investment);

    System. out. println ("an interest rate of "+interest+"% compounded annually:");

    double Value = investment * (1+interest);

    double cont5 = Value;

    //int Value = getValue (investment, interest, 5);

    for (int year = 1; year < = 4; year++) {

    cont5 = cont5 * Value;

    }

    System. out. println ("In 5 years the value is : "+"$"+cont5);

    double cont10 = Value;

    //Value = getValue (investment, interest, 10);

    for (int year = 1; year < = 9; year++) {

    cont10 = cont10 * Value;

    }

    System. out. println ("In 10 years the value is : "+"$"+cont10);

    double cont20 = Value;

    //Value = getValue (investment, interest, 20);

    for (int year = 1; year < = 19; year++) {

    cont20 = cont20 * Value;

    }

    System. out. println ("In 20 years the value is : "+"$"+cont20);

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that takes two numbers from the Java console representing, respectively, an investment and an interest rate (you will ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers