//This program will calculate the compound interest.
import java.io.*;
import java.text.*;
public class Program08
{
public static void main (String args[])
throws java.io.IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
DecimalFormat roundMyDecimal=new DecimalFormat("0.00");
float amount;
float principal;
float interest;
float compounds;
float years;
System.out.print("Enter the principal: "); // inputs principal.
principal=Float.parseFloat(br.readLine());
System.out.print("Enter the number of years: "); // inputs years.
years=Float.parseFloat(br.readLine());
System.out.print("Enter the number of times compounded: "); // inputs number of compounds in a year.
compounds=Float.parseFloat(br.readLine());
System.out.print("Enter the interest rate: "); // inputs interest rate.
interest=Float.parseFloat(br.readLine());
amt=(float)principal*Math.pow(1+interest,years);
System.out.print("\nSaving $" + principal " for " + years " years at " + roundMyDecimal.format (interest) " interest compounded " + compounds " times a year will result in $" + amount);
}
}
KAUL 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.