Professional Documents
Culture Documents
getBalance(). so when user want to withraw the amount then if check if sufficient
balance is not available then throw custom exception for Insufficient Balance.
package assignments;
import java.util.Scanner;
balance=4000+deposite;
System.out.println("Balance: "+balance);
}
static void withdraw() {
Scanner sc=new Scanner(System.in);
System.out.print("Enter withdraw amount: ");
withdraw=sc.nextInt();
//withdraw=2000;
if(withdraw>balance) {
try {
throw new InSufficientException();
}
catch(InSufficientException i) {
System.out.println(i);
}
}
else {
balance=balance-withdraw;
System.out.println("\nAmount Deducted");
System.out.println("balance: "+balance);
}
}
}
class InSufficientException extends Exception{
private String msg;
public InSufficientException() {
msg="\nInSufficient Balance Exception";
}
@Override
public String toString() {
return msg;
}
}