-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankSystem.java
More file actions
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
abstract class Account {
private String accountNumber;
private double balance;
public Account(String accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
public double getBalance() {
return balance;
}
public void deposit(double amount) {
balance += amount;
System.out.println("Deposited: " + amount);
}
protected void setBalance(double balance) {
this.balance = balance;
}
abstract void withdraw(double amount);
public void display() {
System.out.println("Account No: " + accountNumber);
System.out.println("Balance: " + balance);
}
}
class SavingsAccount extends Account {
private final double BALANCE = 500;
public SavingsAccount(String accNo, double balance) {
super(accNo, balance);
}
@Override
public void withdraw(double amount) {
if (getBalance() - amount >= BALANCE) {
setBalance(getBalance() - amount);
System.out.println("Withdrawn from Savings: " + amount);
} else {
System.out.println("Minimum balance must be maintained!");
}
}
}
class CurrentAccount extends Account {
private final double OVERDRAFTLIMIT = -1000;
public CurrentAccount(String accNo, double balance) {
super(accNo, balance);
}
@Override
public void withdraw(double amount) {
if (getBalance() - amount >= OVERDRAFTLIMIT) {
setBalance(getBalance() - amount);
System.out.println("Withdrawn from Current: " + amount);
} else {
System.out.println("Overdraft limit exceeded!");
}
}
}
public class BankSystem {
public static void main(String[] args) {
Account acc1 = new SavingsAccount("SA123", 2000);
Account acc2 = new CurrentAccount("CA456", 1000);
acc1.withdraw(1700);
acc2.withdraw(1800);
acc1.display();
acc2.display();
}
}