Rahmadnet

Exception

Jul 11th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. package Java_Exception;
  2.  
  3. public class MyException extends Exception
  4. {
  5.     // store account information
  6.     private static int acno[] = {1001, 1002, 1003, 1004};
  7.    
  8.     private static String name[] = {"Rahmad", "Wildan", "Andari", "Rahmadi", "Rafi","Wandi"};
  9.    
  10.     private static double bal[] = {10000.00, 12000.00, 5600.0, 999.00, 1100.55};
  11.    
  12.     // default constructor
  13.     public MyException() {
  14.         // TODO Auto-generated constructor stub
  15.     }
  16.    
  17.     // parametrized constructor
  18.     MyException(String str)
  19.     {
  20.         super(str);
  21.     }
  22.    
  23.     // write main
  24.     public static void main(String[] args) {
  25.         try {
  26.             // display the heading for the table
  27.             System.out.println("ACCNO" + "\t" + "CUSTOMER" + "\t" + "BALANCE");
  28.            
  29.             // display the actual account information
  30.             for(int i = 0; i < 5 ; i++)
  31.             {
  32.                 System.out.println(acno[i] + "\t" + name[i] + "\t" + "\t"+ bal[i]);
  33.                
  34.                 // display own exception if balance < 1000
  35.                 if(bal[i] < 1000)
  36.                 {
  37.                     MyException me = new MyException("Balance is less than 1000"); throw me;
  38.                 }
  39.             }
  40.         } // end of try
  41.        
  42.         catch (Exception e) {
  43.             e.printStackTrace();
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment