Skip to content

Commit 8e3b9f1

Browse files
committed
Interest (IPA-35)
1 parent c0c3d6f commit 8e3b9f1

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

IPA29/Calculate_Interest.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import java.util.*;
2+
public class Calculate_Interest
3+
{
4+
public static void main(String[] args)
5+
{
6+
Scanner sc = new Scanner(System.in);
7+
8+
int a = sc.nextInt();sc.nextLine();
9+
double b = sc.nextDouble();sc.nextLine();
10+
double c = sc.nextDouble();sc.nextLine();
11+
Account ac = new Account(a,b,c);
12+
13+
int n = sc.nextInt();
14+
15+
double interest = calculateInterest(ac, n);
16+
17+
System.out.format("%.3f",interest);
18+
19+
}
20+
public static double calculateInterest(Account ac, int n)
21+
{
22+
double per = (ac.getInterestRate()/100)*n;
23+
per = ac.getInterestRate()+per;
24+
return per;
25+
}
26+
}
27+
class Account
28+
{
29+
int id;
30+
double balance;
31+
double interestRate;
32+
33+
public Account(int id, double balance, double interestRate)
34+
{
35+
this.id = id;
36+
this.balance = balance;
37+
this.interestRate = interestRate;
38+
}
39+
40+
public int getId()
41+
{
42+
return id;
43+
}
44+
public void setId(int id)
45+
{
46+
this.id = id;
47+
}
48+
public double getBalance()
49+
{
50+
return balance;
51+
}
52+
public void setBalance(double balance)
53+
{
54+
this.balance = balance;
55+
}
56+
public double getInterestRate()
57+
{
58+
return interestRate;
59+
}
60+
public void setInterestRate(double interestRate)
61+
{
62+
this.interestRate = interestRate;
63+
}
64+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Find total interest of an amount.
2+
3+
Create a class Account with following attributes :
4+
id - int
5+
balance - double
6+
interestRate - double
7+
8+
Take another integer as number of year.
9+
After that calculate total interest using formula:
10+
11+
Percentage = interestRate * 100 / time
12+
Total Interest = Percentage + interestRate

0 commit comments

Comments
 (0)