Categories
Uncategorized

Bank Program

import java.io.*;

import java.util.Scanner;

class LessBalanceException extends Exception
{
LessBalanceException(double amt)
{
System.out.println(“withdrawal of “+amt+”is invalid”);
}
}

class Account {

public String name;
public double bal;

Account(double bal,String n)
{
System.out.println(“\n New account opened \n”);
this.bal=bal;
name=n;
System.out.println(“\n Thank you your new account with account name  “+name+” is created  with minimum balance of “+ bal);

}
}
class account1 extends Account
{
account1(String n)
{
super(500,n);
}
void deposit(double amt)
{
System.out.println(“\n Account balance is :” + bal);

bal+=amt;
System.out.println(” Rs.”+amt+”|- Credited”);
System.out.println(“n new balance is :” + bal);

}
void withdraw(double amt) throws LessBalanceException{
System.out.println(“\n Account balance is :” + bal);
bal-=amt;

if(bal<500){
bal=bal+amt;
throw new LessBalanceException(amt);
}
System.out.println(” Rs.”+amt+”|- debited”);

System.out.println(“\n new balance is :” + bal);
}
void balance()
{
System.out.println(“\n Account holder name  :” + name);
System.out.println(“\n Current balance is :” + bal);

}
}

class bank
{
public static void main(String args[]){

int ch;
String name;
double amt;
boolean b=true;

Scanner sc=new Scanner(System.in);
System.out.println(“\n Enter name:”);
name=sc.next();
account1 ob=new account1(name);

while(b){
System.out.println(“\n menu BANKING OPERATIONS”);
System.out.println(“—————————–“);

System.out.println(“\n  1.Deposit “);
System.out.println(“\n  2.Withdraw”);
System.out.println(“\n  3.Check Balance”);
System.out.println(“\n  4.Exit”);
System.out.println(“\n Enter your choice  : “);
ch=sc.nextInt();

switch(ch){

case 1:
System.out.println(“\n Deposit section”);

System.out.println(“Enter the ammount to deposit”);
amt=sc.nextDouble();
ob.deposit(amt);
break;

case 2:

System.out.println(“Enter the ammount to withdraw”);
amt=sc.nextDouble();
try{
ob.withdraw(amt);
}catch(LessBalanceException e){}

break;

case 3:
System.out.println(“\n Balance Enquire section”);

ob.balance();
break;

case 4:
System.out.println(“\n Exiting”);
b=false;
System.exit(1);

default:
System.out.println(“\n Invalid options retry with options(1-5)”);
break;
}
}
}}