Tuesday, September 27, 2016

// // Leave a Comment

Financial Application: Compound Value

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

Liang Introduction to Java exercise 2.13 solution

/**
 *
 * @Author: Aghatise Osazuwa
 * Website: www.cscprogrammingtutorials.com
 *
 * Exercise 2.13 - Financial Application: Compound Value
 *
 */ 

import java.util.Scanner;

public class CompoundValue {

    public static void main(String[] args) {
        
        //Display Program Information
        System.out.println("This Program Calculates The Compound Value Of An "
                + "Account After The Sixth Month.\n");

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

        //prompt user to enter details
        System.out.println("Enter the monthly saving amount:");
        double savings = input.nextDouble();

        //calculate the account value after the sixth month
        double firstMonth = savings * (1 + 0.00417);
        double secondMonth = (savings + firstMonth) * (1 + 0.00417);
        double thirdMonth = (savings + secondMonth) * (1 + 0.00417);
        double fourthMonth = (savings + thirdMonth) * (1 + 0.00417);
        double fifthMonth = (savings + fourthMonth) * (1 + 0.00417);
        double sixthMonth = (savings + fifthMonth) * (1 + 0.00417);

        //format the sixth month to two decimal places
        sixthMonth = (int) (sixthMonth * 100) / 100.0;

        //display the result
        System.out.println("After the sixth month, the account value is $"
                + sixthMonth + "\n");
    }
}

Click here to see other solutions to Introduction to Java Programming.

0 comments:

Post a 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.

Thanks.