-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodingProblemJavaTest.java
More file actions
36 lines (31 loc) · 997 Bytes
/
codingProblemJavaTest.java
File metadata and controls
36 lines (31 loc) · 997 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
import java.util.Scanner;
class BalanceInsufficientException extends RuntimeException {
public BalanceInsufficientException(String msg){
super(msg);
}
}
class InvalidAmountException extends RuntimeException {
public InvalidAmountException(String msg) {
super(msg);
}
}
public class codingProblemJavaTest {
public static void main(String[] args){
withdraw();
}
static void withdraw(){
double balance=1000.00;
int am;
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Enter Balance to Withdraw");
am = sc.nextInt();
}
if (am<=balance && am%100==0){
System.out.println("Amount successfully withdrawn");
}
else if(am>balance){
throw new BalanceInsufficientException("Amount is greater than balance");
}
else throw new InvalidAmountException("Amount in -ve or not in multiples of 100");
}
}