Skip to content

Commit 8c54792

Browse files
Create CompoundInterestCalculator.java
1 parent 5362822 commit 8c54792

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0 commit comments

Comments
 (0)