-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD3-1.txt
34 lines (28 loc) · 906 Bytes
/
D3-1.txt
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
class Loan{
protected int tenure;
protected float interestRate;
Loan(int tenure, float interestRate){
this.tenure = tenure;
this.interestRate = interestRate;
}
}
class HomeLoan extends Loan{
HomeLoan(){
super(5,8.5f); //invoking super class constructor
}
public double calculateEMI(double principal){
double simpleInterest = (principal * interestRate * tenure) / 100;
double emi = (simpleInterest + principal) / tenure;
int additionalTax = 200;
return emi + additionalTax;
}
}
class ExecuteLoan{
public static void main (String[] args) {
HomeLoan loan = new HomeLoan(); //Runtime polymorphism
double hloan = loan.calculateEMI(2000000);
System.out.println("Home loan emi per year..." + hloan);
}
}
Output:
Home loan emi per year...570200.0