Question
1. Modify the compound-interest application in interest.java (available on Blackboard) to repeat its steps for interest rates of 5%, 6%, 7%, 8%, 9% and 10%.
1. Modify the compound-interest application in interest.java (available on Blackboard) to repeat its steps for interest rates of 5%, 6%, 7%, 8%, 9% and 10%. Use a for loop to vary the interest rate.
interest.java :
// Compound-interest calculations with for. public class Interest { public static void main(String[] args) { double principal = 1000.0; // initial amount before interest double rate = 0.05; // interest rate // display headers System.out.printf("%s%20s%n", "Year", "Amount on deposit"); // calculate amount on deposit for each of ten years for (int year = 1; year <= 10; ++year) { // calculate new amount on deposit for specified year double amount = principal * Math.pow(1.0 + rate, year); // display the year and the amount System.out.printf("%4d%,20.2f%n", year, amount); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started