-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExp73.java
More file actions
47 lines (39 loc) · 1.12 KB
/
Exp73.java
File metadata and controls
47 lines (39 loc) · 1.12 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
interface Bank {
void deposit(double amount);
void withdraw(double amount);
}
class Account implements Bank {
private double balance;
Account(double initialBalance) {
this.balance = initialBalance;
}
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("Deposited: ₹" + amount);
} else {
System.out.println("Invalid deposit amount.");
}
}
public void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
System.out.println("Withdrawn: ₹" + amount);
} else {
System.out.println("Invalid or insufficient funds for withdrawal.");
}
}
void showBalance() {
System.out.println("Current Balance: ₹" + balance);
}
}
public class Exp73 {
public static void main(String[] args) {
Account account = new Account(1000);
account.showBalance();
account.deposit(500);
account.withdraw(300);
account.withdraw(1500);
account.showBalance();
}
}