- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankSystem.java
More file actions
Latest commit
63 lines (63 loc) · 2.02 KB
/
Copy pathBankSystem.java
File metadata and controls
63 lines (63 loc) · 2.02 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
abstractclassAccount {
privateStringaccountNumber;
privatedoublebalance;
publicAccount(StringaccountNumber, doublebalance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
publicdoublegetBalance() {
returnbalance;
}
publicvoiddeposit(doubleamount) {
balance += amount;
System.out.println("Deposited: " + amount);
}
protectedvoidsetBalance(doublebalance) {
this.balance = balance;
}
abstractvoidwithdraw(doubleamount);
publicvoiddisplay() {
System.out.println("Account No: " + accountNumber);
System.out.println("Balance: " + balance);
}
}
classSavingsAccountextendsAccount {
privatefinaldoubleBALANCE = 500;
publicSavingsAccount(StringaccNo, doublebalance) {
super(accNo, balance);
}
@Override
publicvoidwithdraw(doubleamount) {
if (getBalance() - amount >= BALANCE) {
setBalance(getBalance() - amount);
System.out.println("Withdrawn from Savings: " + amount);
} else {
System.out.println("Minimum balance must be maintained!");
}
}
}
classCurrentAccountextendsAccount {
privatefinaldoubleOVERDRAFTLIMIT = -1000;
publicCurrentAccount(StringaccNo, doublebalance) {
super(accNo, balance);
}
@Override
publicvoidwithdraw(doubleamount) {
if (getBalance() - amount >= OVERDRAFTLIMIT) {
setBalance(getBalance() - amount);
System.out.println("Withdrawn from Current: " + amount);
} else {
System.out.println("Overdraft limit exceeded!");
}
}
}
publicclassBankSystem {
publicstaticvoidmain(String[] args) {
Accountacc1 = newSavingsAccount("SA123", 2000);
Accountacc2 = newCurrentAccount("CA456", 1000);
acc1.withdraw(1700);
acc2.withdraw(1800);
acc1.display();
acc2.display();
}
}