0% found this document useful (0 votes)
127 views

Program 26

The document describes a Java program that implements a simple banking application. It creates an Account class with deposit and withdraw methods. The main method initializes an account with Rs. 1000, then withdraws Rs. 400, Rs. 300, and attempts to withdraw Rs. 500 which throws a custom "Not Sufficient Fund" exception.

Uploaded by

Rushi Pandav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Program 26

The document describes a Java program that implements a simple banking application. It creates an Account class with deposit and withdraw methods. The main method initializes an account with Rs. 1000, then withdraws Rs. 400, Rs. 300, and attempts to withdraw Rs. 500 which throws a custom "Not Sufficient Fund" exception.

Uploaded by

Rushi Pandav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical - 26

Aim :- Write an small application in Java to develop Banking


Application in which user deposits the amount Rs 1000.00 and then
start withdrawing of Rs 400.00, Rs 300.00 and it throws exception
"Not Sufficient Fund" when user withdraws Rs. 500 thereafter.

class MyException extends Exception


{
public String toString()
{
return "Not Sufficient Fund.";

}
}

class Account
{
double amount;

Account(double a)
{
amount = a;
}

void deposite(double a)
{
amount = amount + a;
System.out.println(a + " rupees deposited.");
System.out.println("New balance is : " + amount);
}
void withdraw(double a)
{
if((amount - a)<0)
{
System.out.println("Attempt to withdraw " + a + " rupees is
failed.");
try
{
throw new MyException();
}
catch(MyException e)
{
System.out.println(e);
}
}
else
{
amount = amount -a;
System.out.println(a + " rupees withdrawn.");
System.out.println("New balance is : " + amount);
}

}
}

public class Example


{
public static void main(String[] args)
{
Account a1 = new Account(1000);
a1.withdraw(400.00);
a1.withdraw(300.00);
a1.withdraw(500.00);
}
}

Output:

400.0 rupees withdrawn.


New balance is : 600.0
300.0 rupees withdrawn.
New balance is : 300.0
Attempt to withdraw 500.0 rupees is failed.
Not Sufficient Fund.

You might also like