public class interest {
public void calculate(int principle, int year, double interestRate, int terms) {
double sinterest = ((500000 * 3.5 * 10) / 100);
double amount = principle * Math.pow(1 + (interestRate / terms), terms * year);
double cinterest = amount - principle;
System.out.println("Simple interest on Taka. 500000.00 in " + year + " years = Taka "+sinterest);
System.out.println("Interest on Taka. 500000.00 in " + year + " years compounded annually = Taka. "+cinterest);
System.out.println("Interest on Taka. 500000.00 in " + year + " years compounded semi-annually = Taka. "+cinterest);
System.out.println("Interest on Taka. 500000.00 in " + year + " years compounded quarterly = Taka. "+cinterest);
System.out.println("Interest on Taka. 500000.00 in " + year + " years compounded monthly = Taka. "+cinterest);
System.out.println("Interest on Taka. 500000.00 in " + year + " years compounded daily = Taka. "+cinterest);
}
public static void main(String args[]) {
interest obj = new interest();
obj.calculate(500000, 10, 0.035, 4); //principle: 500000, year: 10, interest: 0.035, terms: 4
}
}
电流输出:
Simple interest on Taka. 500000.00 in 10 years = Taka 175000.0
Interest on Taka. 500000.00 in 10 years compounded annually = Taka. 208454.41896556818
Interest on Taka. 500000.00 in 10 years compounded semi-annually = Taka. 208454.41896556818
Interest on Taka. 500000.00 in 10 years compounded quarterly = Taka. 208454.41896556818
Interest on Taka. 500000.00 in 10 years compounded monthly = Taka. 208454.41896556818
Interest on Taka. 500000.00 in 10 years compounded daily = Taka. 208454.41896556818
所有复利(每年、半年、季度、每月和每日)打印相同的值(季度=塔卡。208454.42). 它应该与预期的输出不同。
预期产量:
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
**
我是否需要添加更多行并更新“term”值?
**
obj.calculate(500000, 10, 0.035, 4); //principle: 500000, year: 10, interest: 0.035, terms: 4
1条答案
按热度按时间ar5n3qh51#
试试这个。
和
输出: