Space for google add

Define a class SavingAccount .Raise user defined InsufficientFundsException when balance is not sufficient for withdraw operation.

  


 Define a class SavingAccount (acNo, name, balance). Define appropriate constructors and operations withdraw(), deposit() and viewBalance(). The minimum balance must be 500. Create an object and perform operations. Raise user defined InsufficientFundsException when balance is not sufficient for withdraw operation.


import java.util.*;

import java.io.*;

class InsufficientFundsException extends Exception

{

InsufficientFundsException()

{

System.out.println("Insufficient bank balnace.");

}

}

class SavingAcc extends Exception

{

double accn;

String name;

float balance;

SavingAcc()

{

accn=0;

name="";

balance=0;

}

void accept()

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter account no, name and balance :");

accn=sc.nextDouble();

name=sc.next();

balance=sc.nextFloat();

}

void display()

{

System.out.println("Account No :"+accn);

System.out.println("Name :"+name);

System.out.println("Balance :"+balance);

}

public void viewbalance()

{

System.out.println("Balance :"+balance);

}

public void deposit()

{ Scanner sc=new Scanner(System.in);

System.out.println("Enter amount for deposit :");

float amt=sc.nextFloat();

balance=balance+amt;

System.out.println("Balance :"+balance);

}

public void withdraw()

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter amount for withdraw :");

float amt=sc.nextFloat();

try

{

if(balance-amt>=500)

{

balance=balance-amt;

System.out.println("Balance :"+balance);

}

else

throw new InsufficientFundsException();

}

catch(Exception e)

{

}

}

}


class ex4setb2

{

public static void main(String args[])

{

int ch;

SavingAcc sc=new SavingAcc();

Scanner s=new Scanner(System.in);

sc.accept();

sc.display();

do

{

System.out.println("1.View Balance");

System.out.println("2.Withdraw");

System.out.println("3.Deposit");

System.out.println("4.Quit");

System.out.println("Enter choise :");

ch=s.nextInt();

switch(ch)

{

case 1:

sc.viewbalance();

break;

case 2:


    sc.withdraw();

break;

case 3:

sc.deposit();

break;

case 4: System.exit(0);

break;

}

} while(ch<5);

}

}


Post a Comment

0 Comments