Custom Exception – Bank Withdrawal: A customer goes to the ATM to withdraw money from his account. The maximum withdrawal limit in ICICI bank for a day is Rs. 25,000.
Write a program that accepts the withdrawal amount from the customer as input. When the amount entered by the user is greater than the withdrawal limit (Rs. 25000), a custom exception named MinimumAccountBalance is thrown. Use exception handling mechanisms to handle this exception.
Input Format:
The input consists of a double value which corresponds to the amount to withdraw.
Output Format:
If the amount to withdraw is less than Rs.25,000 print “Amount Withdrawn Successfully”. Else throw the custom exception.
Refer to sample input and output for formatting specifications.
Note: All text in bold corresponds to input and the rest corresponds to output.
Sample Input and Output 1:
Enter amount to withdrawal
5000
Amount Withdrawn Successfully
Sample Input and Output 2:
Enter amount to withdrawal
26000
Caught MinimumAccountBalance: Minimum Account Balance Exception
Solution
import java.util.Scanner;
class MinimumAccountBalance extends Exception {
public MinimumAccountBalance(String message) {
super(message);
}
}
//sauravhathi
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//sauravhathi
System.out.println("Enter amount to withdrawal");
double amount = sc.nextDouble();
try {
if(amount>25000) {
throw new MinimumAccountBalance("Minimum Account Balance Exception");
}
else {
//sauravhathi
System.out.println("Amount Withdrawn Successfully");
}
}
catch(MinimumAccountBalance e) {
System.out.println("Caught MinimumAccountBalance: "+e.getMessage());
}
}
//sauravhathi
}Happy Learning – If you require any further information, feel free to contact me.
![[Solved] Custom Exception - Bank Withdrawal with Java [Solved] Custom Exception - Bank Withdrawal with Java](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Custom-Exception-Bank-Withdrawal-with-Java.png)

![[Solved] You are given two strings str1 and str2. Find the minimum number of edits (operations) that can be performed on str1 to transform it into str2 with Java](https://realcoder.techss24.com/wp-content/uploads/2022/08/Solved-You-are-given-two-strings-str1-and-str2.-Find-the-minimum-number-of-edits-operations-that-can-be-performed-on-str1-to-transform-it-into-str2-with-Java-300x200.png)
![[Solved] PTM tomorrow in Cambridge School. Teachers want to show the grades](https://realcoder.techss24.com/wp-content/uploads/2023/02/Solved-PTM-tomorrow-in-Cambridge-School.-Teachers-want-to-show-the-grades-300x169.png)