-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.java
More file actions
41 lines (41 loc) · 1.14 KB
/
Copy pathBank.java
File metadata and controls
41 lines (41 loc) · 1.14 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
package BankAccounts;
import java.util.Scanner;
public class Bank {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Welcome to IBank!");
System.out.println("Enter balance");
int balance=sc.nextInt();
System.out.println("Enter amount");
int amount=sc.nextInt();
sc.close();
Account b1=new Account(balance,amount);
try{
b1.withdraw();
}
catch (InsufficientBalanceException e){
System.out.println(e.getMessage());
}
}
}
class InsufficientBalanceException extends Exception{
InsufficientBalanceException(String message){
super(message);
}
}
class Account{
int balance;
int amount;
Account(int balance,int amount){
this.balance=balance;
this.amount=amount;
}
public void withdraw() throws InsufficientBalanceException{
if(amount>balance){
throw new InsufficientBalanceException("InsufficientBalanceException: Cannot withdraw Rs. "+amount+",balance Rs. "+balance);
}
else{
System.out.println("Withdrawal successful");
}
}
}