-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank_Withdraw.java
More file actions
40 lines (32 loc) · 1.05 KB
/
Bank_Withdraw.java
File metadata and controls
40 lines (32 loc) · 1.05 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
/* Write a java program on user defined exceptions. */
package User_Defined_Exceptions;
import java.util.Scanner;
// Custom exception class
class MinimumAccountBalance extends Exception {
String message;
public MinimumAccountBalance(String message) {
this.message = message;
}
public String toString() {
return message;
}
}
public class Bank_Withdraw {
static double current_balance = 100; // can give any amount
public static void main(String[] args) throws MinimumAccountBalance{
Scanner scan = new Scanner(System.in);
System.out.println("Enter amount for withdrawal");
int n = scan.nextInt();
scan.close();
try {
if (current_balance < n) {
throw new MinimumAccountBalance("Insufficient funds ! your Current balance is " + current_balance);
}
else {
System.out.println("Please Take The Money : " + n);
}
} catch (MinimumAccountBalance mab) {
mab.printStackTrace();
}
}
}