-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWithdraw.java
More file actions
55 lines (37 loc) · 1.21 KB
/
Withdraw.java
File metadata and controls
55 lines (37 loc) · 1.21 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
package com.assignment;
import java.util.Scanner;
import com.assignment.exception.InsufficientBalanceException;
public class Withdraw {
int balance=0, amount;
static Scanner scan=new Scanner(System.in);
public void withdrawAmount() throws InsufficientBalanceException {
System.out.println("Enter Amount");
amount=scan.nextInt();
balance=balance-amount;
if(balance<=0) {
throw new InsufficientBalanceException("Insufficient Balance Exception");
}
else {
System.out.println("Withdraw Successfully and balance is: " + balance);
}
}
public void depositAmount() {
System.out.println("Enter Amount");
balance=scan.nextInt();
balance=balance+amount;
System.out.println("Deposited Successfully and balance is: " + balance);
}
public static void main(String[] args) throws InsufficientBalanceException {
Withdraw withdraw=new Withdraw();
while(true) {
System.out.println("Enter 1 for deposit, 2 for withdraw, 3 for exit");
int input=scan.nextInt();
switch(input) {
case 1 : withdraw.depositAmount();
break;
case 2 : withdraw.withdrawAmount();
break;
case 3 : System.exit(1);
}
}}
}