-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankDemo.java
More file actions
37 lines (32 loc) · 940 Bytes
/
Copy pathBankDemo.java
File metadata and controls
37 lines (32 loc) · 940 Bytes
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
interface Bank {
void deposit(double amount);
void withdraw(double amount);
}
class Account implements Bank {
private double balance;
Account(double initialBalance) {
this.balance = initialBalance;
}
@Override
public void deposit(double amount) {
balance += amount;
System.out.println("Deposited: $" + amount + ", New Balance: $" + balance);
}
@Override
public void withdraw(double amount) {
if (amount > balance) {
System.out.println("Insufficient Balance!");
} else {
balance -= amount;
System.out.println("Withdrawn: $" + amount + ", New Balance: $" + balance);
}
}
}
public class BankDemo {
public static void main(String[] args) {
Account acc = new Account(1000);
acc.deposit(500);
acc.withdraw(200);
acc.withdraw(1500);
}
}