-
Notifications
You must be signed in to change notification settings - Fork 6
/
Endowment plan – Inheritance.java
155 lines (148 loc) · 4.52 KB
/
Endowment plan – Inheritance.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
public class EducationalEndowment extends Endowment{
private String educationalInstitution;
private String educationalDivision;
public EducationalEndowment(String endowmentId, String holderName, String
endowmentType, String registrationDate, String educationalInstitution, String
educationalDivision){
super(endowmentId,holderName,endowmentType, registrationDate);
this.educationalInstitution=educationalInstitution;
this.educationalDivision=educationalDivision;
}
public String getEducationalInstitution(){
return educationalInstitution;
}
public void setEducationalInstitution(String educationalInstitution){
this.educationalInstitution=educationalInstitution;
}
public String getEducationalDivision(){
return educationalDivision;
}
public void setEducationalDivision(String educationalDivision){
this.educationalDivision=educationalDivision;
}
public double calculateEndowment(){
int endowmentAmount=0;
if(educationalDivision.equalsIgnoreCase("School")){
endowmentAmount=30000;
}
else if (educationalDivision.equalsIgnoreCase("UnderGraduate")){
endowmentAmount=60000;
}
else{
endowmentAmount=90000;
}
return endowmentAmount;
}
}
//================================================//
public abstract class Endowment {
private String endowmentId;
private String holderName;
private String endowmentType;
private String registrationDate;
public Endowment(String endowmentId, String holderName, String
endowmentType, String registrationDate){
this.endowmentId=endowmentId;
this.holderName=holderName;
this.endowmentType=endowmentType;
this.registrationDate=registrationDate;
}
public String getEndowmentId(){
return endowmentId;
}
public void setEndowmentId(String endowmentId){
this.endowmentId=endowmentId;
}
public String getHolderName(){
return holderName;
}
public void setHolderName(String holderName){
this.holderName=holderName;
}
public String getEndowmentType(){
return endowmentType;
}
public void setEndowmentType(String endowmentType){
this.endowmentType=endowmentType;
}
public String getRegistrationDate(){
return registrationDate;
}
public void setRegistrationDate(String registrationDate){
this.registrationDate=registrationDate;
}
public abstract double calculateEndowment();
}
//=================================================//
public class HealthEndowment extends Endowment{
private String healthCareCenter;
private int holderAge;
public HealthEndowment(String endowmentId, String holderName, String
endowmentType, String registrationDate, String healthCareCenter, int holderAge){
super(endowmentId,holderName,endowmentType,registrationDate);
this.healthCareCenter=healthCareCenter;
this.holderAge=holderAge;
}
public String getHealthCareCenter(){
return healthCareCenter;
}
public void setHealthCareCenter(String healthCareCenter){
this.healthCareCenter=healthCareCenter;
}
public int getHolderAge(){
return holderAge;
}
public void setHolderAge(int holderAge){
this.holderAge=holderAge;
}
public double calculateEndowment(){
int endowmentAmount=0;
if(holderAge<=30){
endowmentAmount=120000;
}
else if (holderAge>30 && holderAge<60){
endowmentAmount=200000;
}
else{
endowmentAmount=500000;
}
return endowmentAmount;
}
}
//=====================================================//
import java.util.Scanner;
public class UserInterface {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Endowment Id");
String endowmentId=sc.nextLine();
System.out.println("Enter Holder Name");
String holderName=sc.nextLine();
System.out.println("Enter Endowment Type");
String endowmentType=sc.nextLine();
System.out.println("Enter Registration Date");
String registrationDate=sc.nextLine();
if(endowmentType.equalsIgnoreCase("Educational")){
System.out.println("Enter Educational Institution");
String educationalInstitution=sc.nextLine();
System.out.println("Enter Educational Division");
String educationalDivision=sc.nextLine();
EducationalEndowment educationalEndowment = new
EducationalEndowment(endowmentId,holderName,endowmentType,registrationDate,educatio
nalInstitution,educationalDivision);
System.out.println("Endowment Amount
"+educationalEndowment.calculateEndowment());
}
else{
System.out.println("Enter Health Care Center");
String healthCenter=sc.nextLine();
System.out.println("Enter Holder Age");
int holderAge=Integer.parseInt(sc.nextLine());
HealthEndowment healthEndowment=new
HealthEndowment(endowmentId,holderName,endowmentType,registrationDate,healthCenter,
holderAge);
System.out.println("Endowment Amount
"+healthEndowment.calculateEndowment());
}
}
}