-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD2-14.txt
45 lines (38 loc) · 1.36 KB
/
D2-14.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
35
36
37
38
39
40
41
42
43
44
45
class Loan{
public double calculateEMI(double principal){
double simpleInterest = (principal * 8.5 * 5) / 100;
return (simpleInterest+principal)/5;
}
}
class HomeLoan extends Loan {
// method overriden
public double calculateEMI(double principal){
int additionalTax = 200;
double simpleInterest = (principal * 7.5 * 20) / 100;
double emi = (simpleInterest + principal) / 20;
return emi+additionalTax;
}
}
class VehicleLoan extends Loan {
// method overriden
public double calculateEMI(double principal){
int additionalTax = 200;
double simpleInterest = (principal * 9.5 * 10) / 100;
double emi = (simpleInterest + principal) / 10;
return emi+additionalTax;
}
}
class ExecuteLoan{
public static void main(String[] args){
Loan loan = null;
loan = new HomeLoan(); //Runtime Polymorphism
double hloan = loan.calculateEMI(2000000);
loan = new VehicleLoan(); //sup class reference holding sub class Object
double vloan = loan.calculateEMI(100000);
System.out.println("Home loan emi per year is..." + hloan);
System.out.println("Vehicle loan emi per year is..." + vloan);
}
}
Output:
Home loan emi per year is...250200.0
Vehicle loan emi per year is...19700.0