-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbankEgwithInterface.java
More file actions
152 lines (127 loc) · 4.87 KB
/
bankEgwithInterface.java
File metadata and controls
152 lines (127 loc) · 4.87 KB
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
interface WorldBank {
void showBalance();
double withdraw(double amount);
double deposite(double amount);
}
interface RBI extends WorldBank {
double ROI = 4.0 / 100;
double calculateYearlyInterset();
}
class PhoneNumber {
String countryCode;
String phu;
public PhoneNumber(String countryCode, String phu) {
this.countryCode = countryCode;
this.phu = phu;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getPhu() {
return phu;
}
public void setPhu(String phu) {
this.phu = phu;
}
@Override
public String toString() {
return "PhoneNumber =" + countryCode + "-" + phu;
}
}
class generalAccount1 implements RBI{
String accountHolderName;
double accountBalance;
int accountNumber;
PhoneNumber phNum;
public generalAccount1(String accountHolderName, double accountBalance, int accountNumber, PhoneNumber phNum) {
this.accountHolderName = accountHolderName;
this.accountBalance = accountBalance;
this.accountNumber = accountNumber;
this.phNum = phNum;
}
public String getAccountHolderName() {
return accountHolderName;
}
public void setAccountHolderName(String accountHolderName) {
this.accountHolderName = accountHolderName;
}
public int getAccountNumber() {
return accountNumber;
}
public void showBalance() {
System.out.println("Account balance is:" + this.accountBalance);
}
public double withdraw(double amount) {
if (this.accountBalance < amount) {
System.out.println("Balance is '0'");
return this.accountBalance;
}
this.accountBalance -= amount;
return this.accountBalance;
}
public double deposite(double amount) {
this.accountBalance += amount;
return this.accountBalance;
}
public double calculateYearlyInterset() {
return this.accountBalance * ROI;
}
@Override
public String toString() {
return "\nAccountNumber=" + accountNumber + "\nAccountHolderName=" + accountHolderName
+"\nAccountBalance=" + accountBalance + "\n"+phNum;
}
}
class SBIaccount extends generalAccount1 {
public SBIaccount(String accountHolderName, double accountBalance, int accountNumber,PhoneNumber phoneNumber ) {
super(accountHolderName, accountBalance + 200 , accountNumber,phoneNumber); // an amount credited to a new account
}
void displayFeatures() {
System.out.println("\nIf you create an account in next 30 day you will get Rs. 200 as an amount credited to a new account in SBI\n");
}
}
class ICICIaccount extends generalAccount1 {
public ICICIaccount(String accountHolderName, double accountBalance, int accountNumber,PhoneNumber phoneNumber ) {
super(accountHolderName, accountBalance + 200 , accountNumber,phoneNumber); // an amount credited to a new account
}
@Override
public double calculateYearlyInterset() {
return this.accountBalance * (ROI+(2.0/100)); //additionalInterest - 2%
}
void displayFeatures() {
System.out.println("\nYou will get 2% more interest with opening a new ICICI account\n");
}
}
public class bankEgwithInterface {
public static void main(String[] args) {
PhoneNumber phoneNInd = new PhoneNumber("+91", "12345657890");
SBIaccount sbi = new SBIaccount("Ashwesh", 0.0, 1, phoneNInd);
PhoneNumber phoneNUSA = new PhoneNumber("+1", "12151455");
ICICIaccount icici = new ICICIaccount("ABC", 0.0, 1,phoneNUSA);
// SBI operations
System.out.println("---- Showing SBI feature ----");
sbi.displayFeatures();
System.out.println("---- Showing ICICI feature ----");
icici.displayFeatures();
System.out.println("\nDepositing Rs.1100 in SBI account");
sbi.deposite(1100.0);
System.out.println("\n---- SBI account info: ----\n" + sbi + "\n");
System.out.println("Withdrawing Money of Rs. 230");
sbi.withdraw(230);
sbi.showBalance();
System.out.println("\nYearly interset for SBI account:" + sbi.calculateYearlyInterset());
System.out.println("\n---- SBI account info: ----\n" + sbi + "\n");
// Now for ICICI
System.out.println("\nDepositing Rs. 2300 in icici account");
icici.deposite(2300);
System.out.println("\n---- ICICI account info: ----\n" + icici+"\n");
System.out.println("Withdrawing Money of Rs. 110");
icici.withdraw(110);
icici.showBalance();
System.out.println("\nYearly interset for icici account:" + icici.calculateYearlyInterset());
System.out.println("\n---- ICICI account info: ----\n" + icici+"\n");
}
}