File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ class CompoundInterestCalculator {
4+ public static void main (String [] args ) {
5+
6+ // COMPOUND INTEREST CALCULATOR
7+
8+ Scanner scanner = new Scanner (System .in );
9+
10+ // Declare variables
11+ double principal ;
12+ double rate ;
13+ int timesCompounded ;
14+ int years ;
15+ double amount ;
16+
17+ // User prompts for principal amount, interest rate, compounded time and number of years
18+ System .out .print ("Enter the principal amount (in Rs.): " );
19+ principal = scanner .nextDouble ();
20+
21+ System .out .print ("Enter the interest rate (in %): " );
22+ rate = scanner .nextDouble () / 100 ;
23+
24+ System .out .print ("Enter the number of times compounded per year: " );
25+ timesCompounded = scanner .nextInt ();
26+
27+ System .out .print ("Enter the number of years: " );
28+ years = scanner .nextInt ();
29+
30+ // Calculate the amount
31+ amount = principal * Math .pow (1 +(rate /years ), years *timesCompounded );
32+ System .out .printf ("The amount after %d years: Rs.%.2f" , years , amount );
33+
34+ scanner .close ();
35+
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments