Tuesday, October 4, 2016

// // 1 comment

Exercise 2.21 - Financial Application: Calculate Future Investment Value

The program below is the solution to Liang's Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.21.

 * @Author: Aghatise Osazuwa
 * Website: www.cscprogrammingtutorials.com
 * Exercise 2.21 - Financial application: calculate future investment value

import java.util.Scanner;

public class Ex02_21 {

    public static void main(String[] args) {
        // Display Program Information
        System.out.println("This Program Calculates The Future Investment Value"
                + " of Investment.\n");

        // create Scanner 
        Scanner input = new Scanner(System.in);

        // prompt user to enter details
        System.out.println("Enter investment amount:");
        double investmentAmount = input.nextDouble();
        System.out.println("Enter annual interest rate in percentage:");
        double monthlyInterestRate = input.nextDouble();
        System.out.println("Enter number of years:");
        double numberOfYears = input.nextDouble();

        // calculate s using the formula futureInvestmentValue = 
        // investmentAmount x (1 + monthlyInterestRate)^numberOfYears*12
        double futureInvestmentValue =
                investmentAmount * Math.pow((1 + (monthlyInterestRate / 1200)), (numberOfYears * 12));
        // format futureInvestmentValue to two decimal places
        futureInvestmentValue = (int) (futureInvestmentValue * 100) / 100.0;

        // display the result
        System.out.println("Accumulated value is $" + futureInvestmentValue + "\n");
Ex02.21 - Liang introduction to Java programming
Program output
Click here to see other solutions to Introduction to Java Programming.

1 comment:

DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately. To get notified of replies or follow-up comments, click the box next to notify me.