Question

In: Computer Science

When a bank account pays compound interest, it pays interest not only on the principal amount...

When a bank account pays compound interest, it pays interest not only on the principal amount that was deposited into the account, but also on the interest that has accumulated over time. Suppose you want to deposit some money into a savings account, and let the account earn compound interest for a certain number of years. The formula for calculating the balance of the account after a specified number of years is:

A=P (1+rn)ntA=P (1+rn)nt

The terms in the formula are:

  • A is the amount of money in the account after the specified number of years.

  • P is the principal amount that was originally deposited into the account.

  • r is the annual interest rate.

  • n is the number of times per year that the interest is compounded.

  • t is the specified number of years.

Write a program that makes the calculation for you. The program should ask the user to input the following:

  • The amount of principal originally deposited into the account

  • The annual interest rate paid by the account

  • The number of times per year that the interest is compounded (For example, if interest is compounded monthly, enter 12. If interest is compounded quarterly, enter 4.)

  • The number of years the account will be left to earn interest

Once the input data has been entered, the program should calculate and display the amount of money that will be in the account after the specified number of years.

Can someone do this program in Java.

Solutions

Expert Solution

Hi. I have answered similar questions before. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: If you want the GUI version of this program, let me know, I have the code.

// CompoundInterestCalculator.java

import java.util.Scanner;

public class CompoundInterestCalculator {

      public static void main(String[] args) {

            // defining a Scanner to read input

            Scanner scanner = new Scanner(System.in);

            // asking and reading each input

            System.out.print("Enter principal amount: ");

            double P = scanner.nextDouble();

            System.out.print("Enter annual interest rate: ");

            double r = scanner.nextDouble();

            System.out.print("Enter total period (years): ");

            double t = scanner.nextDouble();

            System.out.print("Enter number of times per year"

                        + " that the interest is compounded: ");

            double n = scanner.nextDouble();

            // calculating total amount

            double A = P * Math.pow(1 + (r / n), n * t);

            // finding interest amount

            double interest = A - P;

            // displaying total amount & total interest earned with a precision of 2

            // digits after decimal point

            System.out.printf("Total amount at maturity: $%.2f\n", A);

            System.out.printf("Total interest earned: $%.2f\n", interest);

      }

}

/*OUTPUT*/

Enter principal amount: 5000

Enter annual interest rate: 0.05

Enter total period (years): 10

Enter number of times per year that the interest is compounded: 12

Total amount at maturity: $8235.05

Total interest earned: $3235.05


Related Solutions

Simple Interest versus Compound Interest First City Bank pays 10% simple interest on its savings account...
Simple Interest versus Compound Interest First City Bank pays 10% simple interest on its savings account balances; whereas, Second City Bank pays 10% interest compounded annually. If you made $6,000 deposit in each bank, how much more money would you earn from your Second City Bank account at the end of 10 years; and, what is the amount for First City Bank? What is the simple interest amount for First City Bank; What is the amount of compound interest for...
A principal amount P0 is deposited in a bank account earning 3% interest compounded monthly. After...
A principal amount P0 is deposited in a bank account earning 3% interest compounded monthly. After 20 years there is $1000 in the account. What was the principal P0? Suppose you want to buy a house for $300, 000, but you only have $100,000. You are able to make an investment that pays 7.3% annual interest. If the interest is compounded continuously, how long will it take before you can buy your new house? You are made an offer. You...
Compound Interest 8.) The amount of P 20,000 was deposited in a bank earning an interest...
Compound Interest 8.) The amount of P 20,000 was deposited in a bank earning an interest of 6.5% per annum. Determine the total amount at the end of 17 years if the principal and interest were not withdrawn during this period. 9.) The amount of P 150,000 was deposited in the bank earning ang interest of 7.5% per annum. Determine the total amount at the end of 16 years, if the principal and interest were not withdrawn during the period....
An amount of $10,000 is deposited into a savings account that pays interest at a rate...
An amount of $10,000 is deposited into a savings account that pays interest at a rate of 7%. If 10 equal annual withdrawals are made from the account starting one year after the money was deposited, how much can be withdrawn so that in the fifth year one would be able to withdraw an additional $1,000 and the account would be depleted after 10 years? Explain verbally in detail and sketch a timeline to illustrate.
Suppose you have savings of $6,697 in a bank account that paysmonthly compound interest of...
Suppose you have savings of $6,697 in a bank account that pays monthly compound interest of 1.4%. You expect towithdraw $338 per month for 9 months from your account, with the first withdrawal starting a month from now. If there are no other deposits or withdrawals, how much money will be left in your account right after your 9th withdrawal? Round your answer to the nearest $1, i.e., round to a whole number.
1. Simple Interest versus Compound Interest First Tappan Bank pays 9 percent simple interest on its...
1. Simple Interest versus Compound Interest First Tappan Bank pays 9 percent simple interest on its savings account balances, whereas First Mullineaux Bank pays 9 percent interest compounded annually. If you made a $7,500 deposit in each bank, how much more money would you earn from your First Mullineaux Bank account at the end of 8 years? 2. Calculating Future Values For each of the following, compute the future value: Present Value Years Interest Rate Future Value $2,328 11 13%...
If your bank account pays annual interest rate of 0.2% and compounds the interest every day,...
If your bank account pays annual interest rate of 0.2% and compounds the interest every day, how much is the future value of $500 saved in the account for 3 years? (include the equation) Hint: Assume there are 365 days per year.
An amount of $15,000 is deposited into an account which pays 5.2% interest. How many periods...
An amount of $15,000 is deposited into an account which pays 5.2% interest. How many periods will it take the account to grow to at least $20,000 if interest is compounded semiannually? If interest is compounded semiannually and simple interest is paid for part of a period, how long before the account is worth exactly $20,000? Use a 360 day year for the simple interest. If interest is compounded continuously, how long before the account is worth exactly $50,000? Use...
1. If you deposit $12,000 in a bank account that pays 9% of interest annually, how...
1. If you deposit $12,000 in a bank account that pays 9% of interest annually, how much will be in your account after 5 years? Round your answer to the nearest cent. 2. What is the present value of a security that will pay $13,000 in 20 years if securities of equal risk pay 12% annually? Round your answer to the nearest cent. 3. Your parents will retire in 27 years. They currently have $400,000 saved, and they think they...
If you deposit $10,000 in a bank account that pays 5% interest annually, how much will...
If you deposit $10,000 in a bank account that pays 5% interest annually, how much will be in your account after 5 years? Do not round intermediate calculations. Round your answer to the nearest cent. What is the present value of a security that will pay $9,000 in 20 years if securities of equal risk pay 7% annually? Do not round intermediate calculations. Round your answer to the nearest cent. Your parents will retire in 28 years. They currently have...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT