Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test1;
- import java.io.*;
- public class CheckingAccount
- {
- private double balance;
- private int number;
- public CheckingAccount(int number)
- {
- this.number = number;
- }
- public void deposit(double amount)
- {
- balance += amount;
- }
- public void withdraw(double amount) throws InsufficientFundsException
- {
- if(amount <= balance)
- {
- balance -= amount;
- System.out.println("Withdraw Done......");
- }
- else
- {
- double needs = amount - balance;
- throw new InsufficientFundsException(needs);
- } }
- public double getBalance()
- { return balance;
- }
- public int getNumber()
- {return number;
- } }
- =================================================================================================================
- package test1;
- public class InsufficientFundsException extends java.lang.Exception
- {
- private double amount;
- public InsufficientFundsException(double amount)
- {
- this.amount = amount;
- }
- public double getAmount()
- {
- return amount;
- }
- }
- ==================================================================================================================
- package test1;
- public class BankDemo
- {
- public static void main(String [] args)
- {CheckingAccount c = new CheckingAccount(101);
- System.out.println("Depositing $500...");
- c.deposit(500.00);
- try
- {
- System.out.println("\nWithdrawing $100...");
- c.withdraw(100.00);
- System.out.println("\nWithdrawing $600...");
- c.withdraw(600.00);
- }catch(InsufficientFundsException e)
- {
- System.out.println("Sorry, but you Balance is insufficent $"
- + e.getAmount());
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement