Question

In: Computer Science

Write a Java method that computes the future investment value at a given interest rate for...

Write a Java method that computes the future investment value at a given interest rate for a specified number of years. Your method should return the future investment value after calculation.
The future investment is determined using the formula below:
    futureInvestmentValue = investmentAmount * (1+monthlyInterestRate)numberOfYears*12
You can use the following method header:
public static double futureInvestmentValue (double investmentAmount, double monthlyInterestRate, int years);

Solutions

Expert Solution

The required java method and the complete source code are given below.Detailed comments are included for better understanding the code.Screen shot of the code and output are also attached.If find any difficulty, feel free to ask in comment section. Please do upvote the answer.Thank you.

Method to calculate future investment value

public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)
{
    //calculating futureInvestmentValue
    //pow() method is used to find the power
    double futureInvestmentValue=investmentAmount *Math.pow((1+monthlyInterestRate),(years*12)) ;
    //returning the result
    return futureInvestmentValue;
}

Formula used

  • futureInvestmentValue = investmentAmount * (1+monthlyInterestRate)^Years*12
  • This is written in java using the statemernt futureInvestmentValue=investmentAmount *Math.pow((1+monthlyInterestRate),(years*12)) ;
  • To find power,pow() function from Math class is used

Source code of the whole program

//Scanner class to read user input
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        //creating scanner object to read user input
        Scanner input=new Scanner(System.in);
        //prompt user to enter different values and read it using appropriate methods of Scanner class
        System.out.print("Enter Investment Amount: ");
        double amount=input.nextDouble();
        System.out.print("Enter Annual Interest : ");
        double annualRate=input.nextDouble();
        //calculating monthlyInterestRate in decimal form
        //dividing annualRate by 12 gives monthlyRate and dividing it by 100 gives its decimal form
        double monthlyRate=annualRate/1200;
        System.out.print("Enter Number of Years: ");
        int years=input.nextInt();
        //calling futureInvestmentValue()function
        double futureInvestValue=futureInvestmentValue(amount,monthlyRate,years);
        //printing the value
        System.out.printf("Future Investment Value: %.2f",futureInvestValue);
    }
    //futureInvestmentValue() function definition
    public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)
    {
        //calculating futureInvestmentValue
        //pow() method is used to find the power
        double futureInvestmentValue=investmentAmount *Math.pow((1+monthlyInterestRate),(years*12)) ;
        //returning the result
        return futureInvestmentValue;
    }
}

Screen shot of the code

Screen shot of the output


Related Solutions

If the current rate of interest is 8% APR, then the future value of an investment...
If the current rate of interest is 8% APR, then the future value of an investment that pays $500 every two years and lasts 20 years is closest to: $11,000 $10,661 $22,881 $20,000
If the current rate interest 7%, then the future value (FV) if an investment that pays...
If the current rate interest 7%, then the future value (FV) if an investment that pays $2299 per year and lasts 18 years is closest to_?
Write a Java method that takes an input string and computes the income minus the expenses....
Write a Java method that takes an input string and computes the income minus the expenses. The income components are indicated by numbers; while the expenses from your spending are numbers starting with a minus sign '-'. The input string may contain lowercase and uppercase letters, as well as other characters. Note that Character.isDigit(char) tests if a char is one of the chars '0', '1', ..., '9'. Also recall that Integer.parseInt(string) converts a string to an int. Test cases :...
QUESTION: For a given positive interest rate, the future value of $100 increases with the passage...
QUESTION: For a given positive interest rate, the future value of $100 increases with the passage of time. Thus, the longer the period of time, the greater the future value. ANSWER OPTIONS: True False You need to specifically state IN THE SUBJECT LINE if the answer is TRUE or FALSE.   EXAMPLES OF INADEQUATE RESPONSES: “I think the answer is False.” OR “The correct answer is “C.” Postings must be no less than 200 words in length to be considered. Any...
Time Value of Money Calculations Given: Principal = $1000 Future Value = $1000 Interest rate =...
Time Value of Money Calculations Given: Principal = $1000 Future Value = $1000 Interest rate = 10% Annuity Pmt = $1000 N = 10 years 1. FV of Lump Sum = ? 2. PV of Lump Sum = ? 3. FV of Annuity = ? 4. FV of Annuity Due = ? 5. PV of Annuity = ? 6. PV of Annuity Due = ? 7. PV of Perpetuity = ?
JAVA PLEASE!! Write a value-returning method, isVowel, that returns the value true if a given character...
JAVA PLEASE!! Write a value-returning method, isVowel, that returns the value true if a given character is a vowel, and otherwise returns false. Also write a program to test your method. 2) Write a program that prompts the user to input a sequence of characters and outputs the number of vowels. (Use the method isVowel written in Programming Exercise 1.)
Perform a future value analysis for the following investment alternatives, using an interest rate of 8%...
Perform a future value analysis for the following investment alternatives, using an interest rate of 8% and a useful life of 10 years. First cost Annual benefits Annual costs Update cost in year 5 Residual value Team A $ 21,500 $ 3,000 the first year with a $ 500 annual increase $ 2,000 $ 3,200 $ 4,000 Team B $ 27,000 $ 4,000 the first year with a $ 400 annual increase $ 3,500 $ 4,500 $ 3,500
Write a method that, given an array of grades stored as double values, computes and return...
Write a method that, given an array of grades stored as double values, computes and return their mean.    Write another method that will return an array of the mean grade obtained by an arbitrary number of student.    This method will take a 2-dimensional array of double values in which each row corresponds to the grade vector    for a different student. You can compute the mean for each row as you did before...    Once you are done,...
1. Calculate the future value of an investment worth $2800 that pays 1.5% simple interest rate...
1. Calculate the future value of an investment worth $2800 that pays 1.5% simple interest rate after 4 years. 2. Derek invested $1000. What would that money grow to in 18 months at a 5% annual simple interest rate? REAL QUESTIONS(IGNORE 1&2) 3. $7500 is deposited at a bank account that pays 3% interest compounded monthly. How much will the account worth after 5 years? 4. Amira deposited $2,000 into a savings account earning 2.6% APR compounded quarterly. How much...
Given a 3 percent interest rate, compute the year 6 future value of deposits made in...
Given a 3 percent interest rate, compute the year 6 future value of deposits made in years 1, 2, 3, and 4 of $1,700, $1,900, $1,900, and $2,200, respectively.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT