Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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.

What I have tried:

Java
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
    }
}


current output:

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


All compounded interest (annually, semi-annually, quarterly, monthly and daily) printing same value(quarterly = Taka. 208454.42). It should be different as the expected output.


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


Do I have to add this line more and update the "term" value?

obj.calculate(500000, 10, 0.035, 4); //principle: 500000, year: 10, interest: 0.035, terms: 4
Posted
Updated 3-Sep-20 19:21pm
v8
Comments
Patrice T 3-Sep-20 13:05pm    
What is the question, the problem ?
ZurdoDev 3-Sep-20 13:52pm    
All you did was repeat yourself. Do you know how to ask a question?
kylin_java 3-Sep-20 14:05pm    
program to calculate compound interest annually, semi-annually, quarterly, monthly and daily
Dave Kreskowiak 3-Sep-20 14:57pm    
Did you want to explain what the problem you're having, or what?
OriginalGriff 3-Sep-20 15:42pm    
What Patrice, ZurdoDev, and Dave are saying is: You have told us what you are required to produce; you have shown us the code you have so far. But what you haven't done is tell use what help you need.
So what is wrong or missing from your app?
Where are you stuck?
What have you tried to "unstick" yourself? What happened when you tried?
What help do you want from us?

Remember, we can't access your HDD; we can't see your screen; we can't read your mind - we only get exactly what you type to work with.

So help us to help you!

Quote:
Do I have to add this line more and update the "term" value?

Yes. That is your problem.

1. Your calculate method will have single print only.
2. You need to define two calculate methods - lets say calculatesi & calculateci separate for simple and compund

You need to call calculate 5 times with different term values. Query is to calculate interest if term is different and rest all the same. So you need to change the term and call method.

Java
obj.calculatesi(500000, 10, 0.035, ?); // term for si 
obj.calculateci(500000, 10, 0.035, ?); // term for ci semiannual
obj.calculateci(500000, 10, 0.035, ?); // term for ci quarterly
obj.calculateci(500000, 10, 0.035, ?); // term for ci monthly
obj.calculateci(500000, 10, 0.035, ?); // term for ci daily

One more thing, Simple Interest and Compound Interest for a year would turn out same and thus if you plan to use one method only, you can but change the print for that one case.

It's a clear assignment. Please go ahead and try it now. With above details, if you are still not clear then I would suggest to start reading and learning from some book or tutorial first and grasp the concepts.

You can start from here: Java Tutorial - basics[^]
 
Share this answer
 
v3
Comments
CPallini 4-Sep-20 2:13am    
5.
Sandeep Mewara 4-Sep-20 4:04am    
:thumbsup:
kylin_java 4-Sep-20 9:44am    
Thank you Very much. I'll try and let you know.
Quote:
Process finished with exit code 0

This means that the code ended normally.
Quote:
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

The missing part of output is simply because you code do not try to output it.
main() request only one output, not 5.
What about adding the 4 other requests ?

[Update]
Quote:
Thank you. I added 4 other lines. which all are printing the same value.

you added code to print all lines, but you keep 1 calculation, so all print the same value.
You need 1 calculation per line.
 
Share this answer
 
v5
Comments
kylin_java 3-Sep-20 22:57pm    
Thank you. I added 4 other lines. which all are printing the same value. It shoud be different for each.

current output:
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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900