-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompoundInterest.java
42 lines (39 loc) · 1.14 KB
/
CompoundInterest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//Program to compute compound interest
import java.util.Scanner;
import java.lang.Math;
class CompoundInterest
{
public static void main(String[] args) {
System.out.print("\nProgram to Compute Compound Interest -----\n");
Interest ca = new Interest();
ca.input_values();
ca.show_interest();
}
}
class Interest
{
double amount, rate, time, total_amount;
public void input_values()
{
Scanner reader = new Scanner(System.in);
System.out.print("\nEnter the principal amount = ");
amount = reader.nextDouble();
System.out.print("\nEnter the interest rate = ");
rate = reader.nextDouble();
System.out.print("\nEnter the total time = ");
time = reader.nextDouble();
compute_interest();
}
public void compute_interest()
{
total_amount = amount*Math.pow(1 + (rate/100.0), time);
}
public void show_interest()
{
System.out.print("\nPrincipal Amount : " + amount );
System.out.print("\nInterest Rate : " + rate );
System.out.print("\nTotal Time : " + time );
System.out.print("\nTotal Amount : " + total_amount);
System.out.print("\nSimple Interest : " + (total_amount - amount));
}
}