problem : a Java program interest.class that calculates the total interest income on amount Taka 5 Lakhs in a period of 10 years. Show the results for simple interest, compounded interest when the compounding is done annually, semi-annually, quarterly, monthly and daily. Assume that the interest rate is 3.5% per year.
I have tried this way,
public class interest {
/*
If interest is compounded yearly, then n = 1;
if semi-annually, then n = 2;
quarterly, then n = 4;
monthly, then n = 12;
weekly, then n = 52;
daily, then n = 365;
and so forth, regardless of the number of years involved.
Also, "t" must be expressed in years, because interest rates are expressed that way.
*/
public void calculate(int p, int t, double r, int n) {
double sinterest = ((500000 * 3.5 * 10) / 100);
double amount = p * Math.pow(1 + (r / n), n * t);
double cinterest = amount - p;
System.out.println("Simple interest on Taka. 500000.00 in " + t + " years=TK "+sinterest);
System.out.println("Compound Interest after " + t + " years: "+cinterest);
System.out.println("Amount after " + t + " years: "+amount);
}
public static void main(String args[]) {
interest obj = new interest();
obj.calculate(500000, 10, 0.035, 4);
}
}
output:
Simple interest on Taka. 500000.00 in 10 years=TK 175000.0
Compound Interest after 10 years: 208454.41896556818
Amount after 10 years: 708454.4189655682
Process finished with exit code 0
Expected output:
Simple interest on Taka. 500000.00 in 10 years = Taka. 175000.00
Interest on Taka. 500000.00 in 10 years compounded annually = Taka. 205299.38
Interest on Taka. 500000.00 in 10 years compounded semi-annually = Taka. 207389.10
Interest on Taka. 500000.00 in 10 years compounded quarterly = Taka. 208454.42
Interest on Taka. 500000.00 in 10 years compounded monthly = Taka. 209172.41
Interest on Taka. 500000.00 in 10 years compounded daily = Taka. 209521.87
0 Answer(s)