Question: You are working on a program that simulates a simple banking system. Write a Java program that includes the following: A method named calculateInterest that
You are working on a program that simulates a simple banking system. Write a Java program that includes the following:
A method named calculateInterest that calculates the compound interest for a given principal amount, interest rate as a decimal and the number of years. The formula for compound interest is:
where:
is the amount after years,
is the principal amount,
is the annual interest rate as a decimal
is the number of times interest is compounded per year,
is the number of years.
In the main method, prompt the user to enter the principal amount, annual interest rate, number of years, and the number of times interest is compounded per year. Use the calculateInterest method to compute and display the final amount after the specified number of years.
Use the header of the method as below:
public static double calculateInterestdouble principal, double rate, int years, int compoundingFrequency
Here is a sample run:
Enter the principal amount:
Enter the annual interest rate as a decimal:
Enter the number of years:
Enter the number of times interest is compounded per year:
After years, the amount will be: $
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
